Centos 8 LEMP WordPress

In this tutorial, How to Install and configure LEMP WordPress running a Centos 8. LEMP an acronym for Linux, Nginx, MySQL, PHP

Environment for Lab

  • Centos 8
  • Nginx
  • MySQL
  • WordPress

1.Nginx Install

The first, Your update for Centos 8.

[root@DevopsRoles vagrant]# dnf update

Next, Install Nginx on Centos 8

[root@DevopsRoles vagrant]# dnf install nginx
# Set to start automatically at reboot 
[root@DevopsRoles vagrant]# systemctl enable  --now nginx
# Check status
[root@DevopsRoles vagrant]# systemctl status nginx

Firewall port setting http (80) Allow https(443)

[root@DevopsRoles vagrant]# firewall-cmd --add-port=80/tcp --permanent
[root@DevopsRoles vagrant]# firewall-cmd --reload

2.Install MySQL

[root@DevopsRoles vagrant]# dnf install @mysql
 # After installation, familiar service start, and automatic start setting
[root@DevopsRoles vagrant]# systemctl start mysqld
[root@DevopsRoles vagrant]# systemctl enable mysqld
 # The initial security settings of mysql
[root@DevopsRoles vagrant]# mysql_secure_installation
# Operation check
[root@DevopsRoles vagrant]# mysql -u root -p

3.Install PHP

[root@DevopsRoles vagrant]# dnf install php-fpm php-cli php-json php-opcache php-xml php-gd php-curl
# php is also set to start automatically
[root@DevopsRoles vagrant]# systemctl enable --now php-fpm

Extension php required to run WordPress on Centos 8

[root@DevopsRoles vagrant]# dnf install php-cli php-json php-opcache php-xml php-gd php-curl php-mysqlnd

4.Database Creation

[root@DevopsRoles vagrant]# mysql -u root -p
# db creation (name can be anything)
SQL> create database wordpressdb;
# Create user, set permissions and reflect settings
SQL> create user wpadmin@localhost identified by 'Stro123@.';
SQL> grant all on wordpressdb.* to wpadmin@localhost;
SQL> flush privileges;
SQL> quit

5.Install WordPress

# Download wordpress
[root@DevopsRoles vagrant]# wget https://wordpress.org/latest.tar.gz
# Create a folder for #wordpress
[root@DevopsRoles vagrant]# mkdir /usr/share/nginx/wp.devopsroles.com
# Decompress
[root@DevopsRoles vagrant]# tar xzf latest.tar.gz -C /usr/share/nginx/wp.devopsroles.com/ --strip-components=1
# Copy configuration file
[root@DevopsRoles vagrant]# cp /usr/share/nginx/wp.devopsroles.com/wp-config-sample.php /usr/share/nginx/wp.devopsroles.com/wp-config.php
# Open configuration file
[root@DevopsRoles vagrant]# vi /usr/share/nginx/wp.devopsroles.com/wp-config.php

Look like wp-config.php file as below:

/** MySQL database name */
define( 'DB_NAME', 'wordpressdb' );
/** MySQL database user name */
define( 'DB_USER', 'wpadmin' );

/** MySQL database password */
define( 'DB_PASSWORD', 'Stro123@.' );

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

/** Database character set when creating database table */
define( 'DB_CHARSET', 'utf8' );

/** Database collation (should not be changed in most cases) */
define( 'DB_COLLATE', '' );

Get the authentication unique key for WordPress.

curl -s https://api.wordpress.org/secret-key/1.1/salt/

Copy and paste the returned contents into wp-config.php

define('AUTH_KEY',         'balabal');
define('SECURE_AUTH_KEY',  'balabal');
define('LOGGED_IN_KEY',    'balabal');
define('NONCE_KEY',        'balabal');
define('AUTH_SALT',        'balabal');
define('SECURE_AUTH_SALT', 'balabal');
define('LOGGED_IN_SALT',   'balabal');
define('NONCE_SALT',       'balabal');

6.Nginx Settings

I have configure nginx for WordPress with content as below:

vi /etc/nginx/conf.d/devopsroles.conf

server {
    listen       80 default_server;
    server_name  devopsroles.com;
    root         /usr/share/nginx/wp.devopsroles.com;

    access_log /var/log/nginx/access_devopsroles.com.log;
    error_log /var/log/nginx/error_devopsroles.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 {
    }
}

Set user and group nginx for folder as below

chown -R nginx:nginx /usr/share/nginx/wp.devopsroles.com/

Restart Nginx

systemctl restart nginx

I have installed success LEMP on Centos 8. Have a good nice 🙂

, , , , ,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.