Install WordPress with Nginx and MySQL 8 on CentOS 8

Want to create a free website or build your personal blog? Ok WordPress Is what you are looking for. After CentOS 8 is released, please follow 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 set up WordPress on CentOS 8 with Nentx and MySQL 8, many prerequisites must be met.

Update system packages

You can use the following commands to update and upgrade system packages on CentOS 8.

dnf update
dnf upgrade

Install LEMP Stack on CentOS 8

Next, make sure the LEMP stack is installed. In other tutorials, we have made a guide on how to install the LEMP stack on CentOS 8. Please click on the link below;

Install LEMP Stack on CentOS 8

Install required PHP extensions

No other PHP extensions required to run WordPress on CentOS 8 are installed in the LEMP guide above.

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

Create WordPress MySQL Database

After setting up the LEMP stack, continue to create database users for MySQL databases and WordPress blogs.

Let’s install the database version first.

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

Be sure to replace the database name, database user, and corresponding password.

Log in to MySQL as root.

mysql -u root -p

Create a WordPress database.

create database wordpressdb;

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

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

Reload the database privilege tables and exit the database.

flush privileges;
quit

Install WordPress 5.x on CentOS 8

WordPress 5.3 is the latest version of this guide. To install the latest version, start from WordPress download page. You can simply use get 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 the WordPress archive content 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 DB_NAME, DB_USER, DB_PASSWORD Use the value you set when you created 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 an authentication unique key and salt. You can simply generate keys and salts from the WordPress secret key service as shown below;

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+}Ao9N#z}UX8_Ms_o<-E6SJ#^z?  ^{8$&H 8H+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$]');

Inside wp-config.phpAnd 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 this;

...
 * @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+}Ao9N#z}UX8_Ms_o<-E6SJ#^z?  ^{8$&H 8H+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 set it as the default (default_server) Block (if you host only 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 to connect to the database, 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

Complete the WordPress installer

Log in to WordPress and complete the setup.

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

Browse and configure your WordPress settings. See the example screenshot below;

After setting, click Install WordPress Complete 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

After the installation is complete, log in to WordPress using the set user credentials.

Install WordPress with Nginx and MySQL 8 on CentOS 8

You go. You have successfully installed WordPress.

This concludes our tutorial on how to install WordPress using Nginx and MySQL 8 on CentOS 8.

.

Sidebar