Install WordPress with Nginx and MySQL 8 on CentOS 8

0
145

Want to create a free website or build your personal blog? Well then WordPress is what you are looking for. With CentOS 8 having been released, follow through this guide to learn how to install WordPress with Nginx and MySQL 8 on CentOS 8.

Install WordPress with Nginx and MySQL 8 on CentOS 8

Prerequisites

In order to setup WordPress on CentOS 8 with Nginx and MySQL 8, there are a number of prerequisites that must be met;

Update System Packages

System packages can be updated and upgraded on CentOS 8 using the commands below;

dnf update
dnf upgrade

Install LEMP Stack on CentOS 8

Next, ensure that you have LEMP stack installed. We have made a guide on how to install LEMP stack on CentOS 8 in our other tutorials. Follow the link below;

Install LEMP Stack on CentOS 8

Install Required PHP Extensions

There are other PHP extensions that are required to run WordPress on CentOS 8 that were not installed on the LEMP guide above.

dnf install php-cli php-json php-opcache php-xml php-gd php-curl

Create WordPress MySQL Database

Once you have your LEMP stack setup, proceed to create MySQL database and the database user for your WordPress blog.

Let us first the Database version installed.

mysql -V
mysql  Ver 8.0.17 for Linux on x86_64 (Source distribution)

Be sure to replace the name of the database, the database user and the password used accordingly.

Login to MySQL as root.

mysql -u root -p

Create a WordPress database.

create database wordpressdb;

Create a WordPress database user and grant all privileges on the database.

create user [email protected] identified by '[email protected]#';
grant all on wordpressdb.* to [email protected];

Reload the database privileges tables and exit the database.

flush privileges;
quit

Install WordPress 5.x on CentOS 8

WordPress 5.3 is the latest version of the writing of this guide. To install the latest version, download WordPress archive from the WordPress downloads page. You can simply use the wget command.

dnf install wget -y
wget https://wordpress.org/latest.tar.gz

Create your web root directory. Replace the names accordingly.

mkdir /usr/share/nginx/wp.kifarunix-demo.com

Next, extract WordPress archive contents to the default Web root directory.

dnf install tar
tar xzf latest.tar.gz -C /usr/share/nginx/wp.kifarunix-demo.com/ --strip-components=1

Verify that the WordPress files are in place.

ls /usr/share/nginx/wp.kifarunix-demo.com/
index.php    wp-activate.php     wp-comments-post.php  wp-cron.php        wp-load.php   wp-settings.php   xmlrpc.php
license.txt  wp-admin            wp-config-sample.php  wp-includes        wp-login.php  wp-signup.php
readme.html  wp-blog-header.php  wp-content            wp-links-opml.php  wp-mail.php   wp-trackback.php

Configure WordPress on CentOS 8

WordPress comes with a sample configuration, wp-config-sample.php. Rename the sample configuration file.

cp /usr/share/nginx/wp.kifarunix-demo.com/wp-config{-sample,}.php

Next, edit the configuration file and set the database connection details,

vi /usr/share/nginx/wp.kifarunix-demo.com/wp-config.php

Replace the DB_NAME, DB_USER, DB_PASSWORD with the values you set while creating the MySQL database for WordPress.

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

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

/** MySQL database password */
define( 'DB_PASSWORD', '[email protected]#' );

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

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

Next, generate authentication unique keys and salts. You can simply generate the keys and salts from WordPress Secret-Key service as follows;

curl -s https://api.wordpress.org/secret-key/1.1/salt/
define('AUTH_KEY',         'B|#MIfD#LtT8].r0$gj[|&kn:[email protected],6fHeP(#u{Kg<q#E}4yuo$goGmF*qxv{}');
define('SECURE_AUTH_KEY',  '<@v!aDzv+I65qI!om67Bc4QA=Wfb|HLr0XhZT;6nVS+`t{&8PI}y}kJ6U[#Hm-x_');
define('LOGGED_IN_KEY',    'JF*T}IXf=8tqx>+}Ao9N#z}UX8_Ms_o<-E6SJ#^z?  ^{8$&H 8H+<a+1$[{$&p+');
define('NONCE_KEY',        'ah6{N4;[email protected]_PO>W`?$^+2Jcvo=hV`e}v}u5+;hPyqw<2b;qyHkXOs$');
define('AUTH_SALT',        '][WrFF`:-.#+}dEJQ.;Q%sl( RiY7:m(-[.sDd3dh|o8S+q>?ak[g6ltHo^V5|]5');
define('SECURE_AUTH_SALT', ')o|KHA^,[email protected][Al;ep$<$a$*emlV+h)l?T+Gc.a!LWZC {DZ buO[B');
define('LOGGED_IN_SALT',   '$-W+/bVu[vkBeWrtu:R-6&cf{]N%z,PBomOP>R=lqCOEt%v]Y>}b]wGp(/yza=ux');
define('NONCE_SALT',       ' VV(UM||}r]G:4#XT;T9:*[email protected]>[`v(m.N383u8pEJ-w*2>h#mh5v`[email protected]}5c:Tc$]');

Within the wp-config.php, replace the following lines with the above.

...
 * @since 2.6.0
 */
define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

/**#@-*/
...

Your configuration should look like;

...
 * @since 2.6.0
 */
/**
 * define( 'AUTH_KEY',         'put your unique phrase here' );
 * define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
 * define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
 * define( 'NONCE_KEY',        'put your unique phrase here' );
 * define( 'AUTH_SALT',        'put your unique phrase here' );
 * define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
 * define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
 * define( 'NONCE_SALT',       'put your unique phrase here' );
 */
define('AUTH_KEY',         'B|#MIfD#LtT8].r0$gj[|&kn:[email protected],6fHeP(#u{Kg<q#E}4yuo$goGmF*qxv{}');
define('SECURE_AUTH_KEY',  '<@v!aDzv+I65qI!om67Bc4QA=Wfb|HLr0XhZT;6nVS+`t{&8PI}y}kJ6U[#Hm-x_');
define('LOGGED_IN_KEY',    'JF*T}IXf=8tqx>+}Ao9N#z}UX8_Ms_o<-E6SJ#^z?  ^{8$&H 8H+<a+1$[{$&p+');
define('NONCE_KEY',        'ah6{N4;[email protected]_PO>W`?$^+2Jcvo=hV`e}v}u5+;hPyqw<2b;qyHkXOs$');
define('AUTH_SALT',        '][WrFF`:-.#+}dEJQ.;Q%sl( RiY7:m(-[.sDd3dh|o8S+q>?ak[g6ltHo^V5|]5');
define('SECURE_AUTH_SALT', ')o|KHA^,[email protected][Al;ep$<$a$*emlV+h)l?T+Gc.a!LWZC {DZ buO[B');
define('LOGGED_IN_SALT',   '$-W+/bVu[vkBeWrtu:R-6&cf{]N%z,PBomOP>R=lqCOEt%v]Y>}b]wGp(/yza=ux');
define('NONCE_SALT',       ' VV(UM||}r]G:4#XT;T9:*[email protected]>[`v(m.N383u8pEJ-w*2>h#mh5v`[email protected]}5c:Tc$]');
/**#@-*/
...

Configure Nginx

Create an Nginx server block for your blog. You can make it the default (default_server) block if you are hosting just one block.

vi /etc/nginx/conf.d/wp.kifarunix-demo.com.conf
server {
    listen       80 default_server;
    server_name  wp.kifarunix-demo.com;
    root         /usr/share/nginx/wp.kifarunix-demo.com;
    
    access_log /var/log/nginx/access_wp.kifarunix-demo.com.log;
    error_log /var/log/nginx/error_wp.kifarunix-demo.com.log;

    index   index.php;

    location / {
        try_files    $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_index index.php;
    }
    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

Next, set the user and group ownership of your site Nginx configuration to nginx user.

chown -R nginx:nginx /usr/share/nginx/wp.kifarunix-demo.com/

If SELinux is running, execute the following commands to allow Nginx connect to DB, send mail and access WordPress configuration files.

setsebool -P httpd_can_network_connect_db=1
setsebool -P httpd_can_sendmail=1
chcon -Rt httpd_sys_content_t /usr/share/nginx/wp.kifarunix-demo.com/

Restart Nginx

systemctl restart nginx

Finalize WordPress Setup

Login to your WordPress and finalize your setup.

Access the your blog using the domain name or IP address; http://domain_name_or_IP.

Go through the WordPress settings and configure them accordingly. See sample screenshot below;

Install WordPress with Nginx and MySQL 8 on CentOS 8

Once done with settings, click Install WordPress to finalize the installation of WordPress on your CentOS 8 server. Be sure to copy the password and save it.

Install WordPress with Nginx and MySQL 8 on CentOS 8

Once the installation is done, login to your WordPress with the user credentials you set up.

Install WordPress with Nginx and MySQL 8 on CentOS 8

There you go. You have successfully installed WordPress.

That brings to the end of our tutorial on how to install WordPress with Nginx and MySQL 8 on CentOS 8.

Other Related Articles

Install LEMP Stack on Debian 10 Buster

Install LEMP Stack with MySQL 8 on Fedora 30/Fedora 29

How To Setup LEMP Stack (Nginx, MariaDB, PHP 7.2) on Ubuntu 18.04

Install WordPress 5 with Nginx on Debian 10 Buster

LEAVE A REPLY

Please enter your comment!
Please enter your name here