
WordPress is the most popular and widely used to create websites, blogs, webshop and much more. PHP processing and MySQL or MariaDB database are used as a backend in WordPress. In this tutorial, we will show you how to install WordPress with Nginx on CentOS 8 system.
Prerequisites
We are going to use LEMP (Linux, Nginx, MariaDB, and PHP) stack with Nginx as web server. So ensure that you met the following prerequisites before start installation process:
- CentOS 8 server with a non-root user with sudo privileges.
- Nginx must installed and configured on your server.
- Your domain name should pointing to your server IP address.
- An SSL certificate installed for your domain. You can install a free Let’s Encrypt SSL certificate as shown in this tutorial.
Step 1 – Create MariaDB database and Grant Permissions
WordPress is using MySQL-based database to store the data and manage site. We will going to create a MariaDB database, MariaDB user and grant permission. If you system don’t have installed MariaDB, you can follow How to Install MariaDB on CentOS 8 tutorial.
At first, log in to MariaDB shell using below command:
mysql -u root -p
It will prompt you to enter password for the root user. You will be logged in on entering correct password.
CREATE DATABASE wordpress;
Type the below command to create a new MariaDB database for your WordPress:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Now you have to create a new MariaDB user by issuing below command:
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'enter-strong-password';
Need to flush the database to take effect in MySQL, type:
FLUSH PRIVILEGES;
Finally, exist from MySQL shell by typing:
EXIT;
Step 2 – Installing Additional PHP Extensions
When setting up our LEMP stack, we only required a very minimal set of extensions in order to get PHP to communicate with MariaDB. WordPress and many of its plugins leverage additional PHP extensions.
We can download and install some of the most popular PHP extensions for use with WordPress by typing:
sudo dnf install php-fpm php-common php-mysqlnd php-gd php-xml php-mbstring php-xml
Step 3 – Downloading and Setup WordPress
Navigate to /tmp directory and download the latest version of WordPress using wget command:
cd /tmp
Now download the latest WordPress setup from the WordPress download page using using below wget command:
wget https://wordpress.org/latest.tar.gz
Once the download is completed, extract the downloaded files using below command:
tar xzvf latest.tar.gz
After that, create the configuration file for WordPress using below command:
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
Then copy all the files to example.com directory using below command:
sudo cp -a /tmp/wordpress/. /var/www/example.com
You need to set the correct permissions so web server can the site’s files and directories. To change the ownership of example.com directory use following chown command:
sudo chown -R nginx:nginx /var/www/example.com
Step 4 – Configure Nginx
You should have installed Nginx on your CentOS machine. We will follow the Nginx recipe from the official Nginx site to create a new server block for our WordPress instance.
Open your text editor and create the following file:
server {
listen 80;
server_name example.com;
root /var/www/html/example.com;
index index.php;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
}
Note : You should replace your real domain name with example.com.
Save and close file. Now check nginx syntax errors by typing:
sudo nginx -t
If there are no errors the output should look like this:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Finally, restart the nginx server :
sudo systemctl restart nginx
Step 5 – Complete the WordPress Installation
Now WordPress is configuration is complete and we can finish remaining installation through web interface.
To do it open your browser and type your domain name and it should show page as following:

Select language which you would like to set and click on continue button to go ahead.
After that it will show below page you just have to click on Let’s Go! button to continue.

On next page it will ask you to enter database connection details. Enter MySQL database and user details which you created previously.

Next hit on the Run the installation button to start installation process.

On next screen, You should enter name of WordPress site and set username and password for your site. Also, enter your email address and select whether you want to discourage search engines from indexing the site (It’s not recommended).

Finally, click on the Install WordPress button and once the installation is finished you will see the below screen:

Hit on Login button you will be redirected to WordPress login page. Now use the username and password which you set in previous step.

After successful login you will be redirected to the WordPress administration dashboard as following:

That’s it. You did and now you can customize your WordPress installation by installing new themes and plugins.
Conclusion
You have successfully installed WordPress with Nginx on CentOS 8 server. I hope you can now easily host your own WordPress website easily.
If you have questions feel free to leave a comment below.
Leave a Reply