How to Install and Setup Nginx, WordPress and Mysql 8 in Rocky Linux/Centos 8

Pinterest LinkedIn Tumblr

In this guide, we will go through Setting up Mysql 8 and the latest wordpress in Centos 8 with Nginx serving traffic and terminating ssl.

WordPress is a free and open-source content management system written in PHP and paired with a MySQL or MariaDB database.
Welcome to the world’s most popular website builder. 42% of the web is built on WordPress.

Related Content:


To follow along this guide, ensure that you have the following:

  • Centos 8 Server
  • Root access or user with sudo access
  • Domain name with A DNS records mapped to the server
  • Internet access from the server

Table of Content

  1. Updating the system
  2. Installing mysql 8 database server
  3. Create Mysql wordpress usr
  4. Install the Nginx Web Server
  5. Install PHP with dependencies
  6. Configure PHP and PHP FPM Settings
  7. Download and Install WordPress
  8. Configuring wordpress
  9. Configure Nginx to serve the site
  10. Complete the WordPress installation

1. Updating the system

Ensure that your system is up to date before proceeding. Use the following command to update the packages:

sudo dnf -y update


$ sudo dnf -y update
Last metadata expiration check: 1:18:02 ago on Tue 17 Aug 2021 11:20:55 AM UTC.
Dependencies resolved.
Nothing to do.

2. Install the MySQL 8 Database Server

Note: To see a detailed guide on installing mysql server, check this guide here.

Now that the system is updated, lets install mysql server. Mysql is available in the Centos 8 repositories as mysql-server package. Install it with this command:

sudo dnf install -y mysql-server

Once installation is done, start the service using this command:

sudo systemctl start mysqld

Enable the service to start on boot:

sudo systemctl enable mysqld

Finally, use the mysql provided secure installation command to set up the initials and the password for mysql user.

sudo mysql_secure_installation

Note down the root password.

3. Create Mysql wordpress user

It is always a good practice to create a dedicated user to use when connecting to the database from mysql. Login as the root user and use these commands to create a user:

Create a database to be used by our site:

create database wp_db;

Create a user:

create user 'wp_user'@'%' identified by 'strongpass';

Grant the created user privileges to the db:

grant all privileges on wp_db.* to 'wp_user'@'%';

Now save the database, user and the password for use when we have wordporess installed.

4. Install the Nginx Web Server

We will use nginx to serve traffic comming in from the designated domain to our wordpress site. We will need to have a virtual host and a domain already mapped to the server that we will use to serve wordpress.

To install Nginx:

sudo dnf -y install nginx

Once the installation is completed, start Nginx and enable it to start automatically after a reboot:

systemctl start nginx
systemctl enable nginx

You can check if the web server is running with this command:

sudo systemctl status nginx


$ sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-08-17 12:40:45 UTC; 21s ago
 Main PID: 70209 (nginx)
    Tasks: 3 (limit: 23800)
   Memory: 5.4M
   CGroup: /system.slice/nginx.service
           ├─70209 nginx: master process /usr/sbin/nginx
           ├─70210 nginx: worker process
           └─70211 nginx: worker process

Aug 17 12:40:45 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Aug 17 12:40:45 nginx[70206]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Aug 17 12:40:45 nginx[70206]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Aug 17 12:40:45 systemd[1]: Started The nginx HTTP and reverse proxy server.

5. Install PHP with dependencies

WordPress is Coded in PHP. We will need php runtime to serve wordpress in our server.

WordPress works in PHP 7.4. The latest version of php is not available in the default Centos Repositories. Let’s enable it with this command:

sudo dnf install dnf-utils

Now enable php 7.4 with this command:

sudo dnf module enable php:remi-7.4

Now let’s install phpuse this command to install:

sudo dnf install -y php \
    php-common \
    php-mbstring \
    php-gd \
    php-intl \
    php-xml \
    php-json \
    php-mysqlnd \

6. Configure PHP and PHP FPM Settings

Global php settings are stored in the /etc/php.ini file. Lets update these settings.

Open php.ini with your favourite text editor, I will use vim

sudo vim /etc/php.ini

Search for the following and update the values like shown below:

post_max_size = 64M
memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 32M
date.timezone = Africa/Nairobi

php-fpm is responsible for serving our php content, its config file is located here: /etc/php-fpm.d/www.conf.

Now open the /etc/php-fpm.d/www.conf configuration file:

sudo vim /etc/php-fpm.d/www.conf

Look for the user and group directives. Make the following changes from apache to nginx:

user = nginx
group = nginx

Save and close the file, then restart the PHP-FPM service to apply the configuration changes:

sudo systemctl restart php-fpm

7. Download and Install WordPress

Now that we have the servers set up, let’s download and install wordpress on the server. The latest release of WordPress can be downloaded from their official website.

Let’s create a directory where our wordpress content willl be served:

sudo mkdir /var/www/dev-citizix

Ensure that the nginx user owns the content:

sudo chown -R nginx.nginx /var/www/dev-citizix

Download the latest wordpress content:

cd /tmp
curl -LO

Sample Output:

$ curl -LO
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15.7M  100 15.7M    0     0  6650k      0  0:00:02  0:00:02 --:--:-- 6647k
$ ls

Extract and move the content to our server directory:

mv wordpress/* /var/www/dev-citizix

8. Configuring wordpress

Now that the wordpress content has been copied to the site directory, lets update the db configuration using the sample file provided.

Switch to the site directory:

cd /var/www/dev-citizix/

Copy your wp-config-sample file to wp-config.php.

cp wp-config-sample.php wp-config.php

Open the config file in a text editor:

vim wp-config.php

Update these vars: DB_NAME, DB_USER, DB_PASSWORD, DB_HOST:


// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'xxx' );

/** MySQL database username */
define( 'DB_USER', 'xxx' );

/** MySQL database password */
define( 'DB_PASSWORD', 'xxx' );

/** MySQL hostname */
define( 'DB_HOST', 'xxx' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

Save the text file once that is done.

Make the Nginx user as the owner of the WordPress directory, so that it has access and is able to serve the files.

sudo chown -R nginx:nginx /var/www/dev-citizix

9. Configure Nginx to serve the site

Now that the config is in place, lets configure an nginx virtual host to serve the content we just added to /var/www/dev-citizix.

Let’s create virtual site in the directory that nginx serves content here /etc/nginx/conf.d:

sudo vim /etc/nginx/conf.d/dev-citizix.conf

Add the following content:

server {
    listen 80;

    root /var/www/dev-citizix;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;

    location = /favicon.ico {
        log_not_found off;
        access_log off;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Ensure that the added config is good by using this command to test:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Once you confirm that everything is OK, restart Nginx for the changes to take effect:

sudo systemctl restart nginx

10. Complete the WordPress installation

Once all steps above are done, the installation from the command line is completed. You can open your favorite web browser and point it to You should get the following screen:

Wordpress Install Screen

WordPress Install Screen

From there you can follow the prompts to set up your wordpress.


We managed to set up Centos 8 with Mysql 8, Php 7.4 and Nginx to serve wordpress in this guide.

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment