Install Nginx, WordPress & MySQL 8 on Rocky/Alma/CentOS 8

Install WordPress with Nginx and MySQL 8 on Rocky Linux, Alma Linux, or CentOS 8: configure PHP 8.3, set up the database, virtual host, and serve your site.

In this guide, we will go through setting up MySQL 8 and the latest WordPress on Rocky Linux, AlmaLinux, or CentOS 8 with Nginx serving the traffic.

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:

Prerequisites

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

  • Rocky Linux 8, AlmaLinux 8, or CentOS Stream 8 server
  • Root access or user with sudo access
  • Domain name with A DNS records mapped to the server
  • Internet access from the server

CentOS Linux 8 reached end of life on 31 December 2021. This guide applies unchanged to its successors — Rocky Linux 8 and AlmaLinux 8 — which track RHEL 8 and are supported until May 2029. Use one of those (or CentOS Stream 8) to follow along on EL8; the same steps also work on the newer EL9/EL10 releases.

Updating the system

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

1
sudo dnf -y update

Output:

1
2
3
4
5
6
$ 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.
Complete!

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:

1
sudo dnf install -y mysql-server

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

1
sudo systemctl start mysqld

Enable the service to start on boot:

1
sudo systemctl enable mysqld

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

1
sudo mysql_secure_installation

Note down the root password.

The mysql-server package in the EL8 AppStream provides MySQL 8.0, which reached end of life in April 2026. For a new deployment consider MySQL 8.4 LTS from the official MySQL yum repository (or MariaDB) — the rest of the steps are the same.

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:

1
create database wp_db;

Create a user:

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

Grant the created user privileges to the db:

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

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

Install the Nginx Web Server

We will use nginx to serve traffic coming 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:

1
sudo dnf -y install nginx

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

1
2
systemctl start nginx
systemctl enable nginx

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

1
sudo systemctl status nginx

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
$ 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 app-server.citizix.com systemd[1]: Starting The nginx HTTP and reverse proxy server...
Aug 17 12:40:45 app-server.citizix.com nginx[70206]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Aug 17 12:40:45 app-server.citizix.com nginx[70206]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Aug 17 12:40:45 app-server.citizix.com systemd[1]: Started The nginx HTTP and reverse proxy server.

Install PHP with dependencies

WordPress is coded in PHP. We will need a PHP runtime to serve WordPress on our server.

WordPress runs best on PHP 8 — as of 2026 the recommended version is PHP 8.3 (PHP 7.4 reached end of life in November 2022). The recent PHP versions are not available in the default EL8 repositories, so we enable the Remi repository:

1
sudo dnf install -y dnf-utils https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Reset the default PHP module stream and enable PHP 8.3:

1
2
sudo dnf module reset php
sudo dnf module enable php:remi-8.3

Now install PHP and the extensions WordPress needs:

1
2
3
4
5
6
7
8
sudo dnf install -y php \
    php-common \
    php-mbstring \
    php-gd \
    php-intl \
    php-xml \
    php-mysqlnd \
    php-fpm

The JSON extension is compiled into PHP 8 core, so the separate php-json package used with PHP 7.x is no longer required.

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

1
sudo vim /etc/php.ini

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

1
2
3
4
5
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:

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

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

1
2
user = nginx
group = nginx

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

1
sudo systemctl restart php-fpm

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 will be served:

1
sudo mkdir /var/www/dev-citizix

Ensure that the nginx user owns the content:

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

Download the latest wordpress content:

1
2
cd /tmp
curl -LO https://wordpress.org/latest.zip

Sample Output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ curl -LO https://wordpress.org/latest.zip

  % 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

latest.zip

Extract and move the content to our server directory:

1
2
unzip latest.zip
mv wordpress/* /var/www/dev-citizix

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:

1
cd /var/www/dev-citizix/

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

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

Open the config file in a text editor:

1
vim wp-config.php

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<?php

// ** 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.

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

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:

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

Add the following content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
server {
    listen 80;

    server_name dev.citizix.com;
    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:

1
2
3
4
$ 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:

1
sudo systemctl restart nginx

This virtual host listens on port 80 (HTTP only). To serve the site over HTTPS, add a Let’s Encrypt certificate afterwards — see How to Secure Nginx with Let’s Encrypt on CentOS 8.

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 your configured domain — https://blog.citizix.com. You should get the wordpress setup screen.

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

Conclusion

We managed to set up Rocky Linux / AlmaLinux / CentOS 8 with MySQL 8, PHP 8.3 and Nginx to serve WordPress in this guide.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy