How to install WordPress with LEMP stack on CentOS 7 VPS. - CloudMinister

WordPress

 

WordPress is one of the most popular and widely used content management systems, blogging platforms in the world. It is popularly used as a Blog, Portfolio Website,  etc.
In this tutorial, you are going to learn how to install WordPress with LEMP (Linux, Nginx, MySQL and PHP)  on CentOS 7 VPS.

 

Table of Content

 

1)  Prerequisites

2) Install MySQL 5.7

3) Configure Database in MySQL

4) Install & Configure PHP 7.2

5) Install Nginx

6) Configure Firewall

7) Configure Nginx File

8) Install WordPress File

9) Test WordPress

1) Prerequisites –

Before you start the installation of WordPress with (LEMP) stack on Centos 7 VPS, you must have one Centos 7 VPS with root privileges on it or you can use sudo for non-root user.  

 You should also run basis command on server to check the following things-:

(i) # df -h  (To check the disk space on the system)

(ii) # cat /etc/os-release  (To verify the version of the VPS)

 

(iii) # yum -y update  (To update all the packages of the VPS)

 

2) Install MySQL 5.7 –

WordPress uses a MySQL database for storage, MySQL is used in stack for storing user details in database.

 For installing MySQL on Centos 7 first you need to enable MySQL repository and then you can install MySQL.

# yum localinstall -y https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

The command used for installing MySQL in CentOS 7 VPS is as follows:

# yum install mysql-server -y

 Then check the MySQL version by typing following command:

 # mysql -V(‘V’ is in uppercase)

 After the installation is completed MySQL will start automatically and you can check it’s status by typing:

# systemctl status mysqld

 If MySQL is not start automatically you can write the following command:

 # systemctl start mysqld

 Before going for the next step you should generate a temporary password to access MySQL root user with the following command:

 # grep ‘temporary password’ /var/log/mysqld.log

Now configure the MySQL secure installation to improve the security by typing the following commands.

# mysql_secure_installation

 Login with the temporary password and assign new password, after that in this configuration it ask several questions you can give Y or N according to your requirement.

i) Change the password for root ? N

ii) Remove anonymous users? Y

iii) Disallow root login remotely? Y

iv) Remove test database and access to it? Y

v)  Reload privilege tables now? Y

3) Configure Database in MySQL –

Now create database for WordPress in MySQL for that first login with MySQL server by using the following command:

 # mysql -u root -p

 And give its password, after that create database in it with the command:

mysql> CREATE DATABASE wordpress;

You can also check that database is created or not with the command:

 mysql> SHOW  DATABASES;

 Now create user and assign him password by using command:

mysql> CREATE USER ‘wordpress’@’localhost’ IDENTIFIED 

 BY ‘Password’;

 After that grant all privileges to the user created under that database with the command:

 mysql> GRANT ALL ON  wordpress.* TO ‘wordpress’@’localhost’;       

 Then flush all privileges on MySQL server with the command:

  mysql> FLUSH PRIVILEGES;

 Now exit from the MySQL server you can use commands:

  mysql> exit;

  mysql> \q;

 
Note-: In MySQL you must end each command with a semicolon(;).

 4) Install & Configure PHP 7.2 –

 PHP is used by WordPress to do various functions done by PHP like calling plugin, calling theme, validating user permissions, checking option, grab from database, etc.

In this Blog we are using PHP 7.2 versionand install it with epel-release with remi repository.

 Firstly, install yum-utils packages using the following command:

# yum -y install yum-utils

 After that, install epel-release package by using command:

# yum -y install epel-release

 Then import remi repository from the command:

 # yum -y install  http://rpms.remirepo.net/enterprise/ remi-release-7.rpm

Enable the remi repository by typing:

# yum-config-manager –enable remi-php72 

 After that install PHP and all required modules by using command:

 # yum -y install php-fpm php-mysql php-mbstring php-xml      php-gd php-cli php-json php-opcache php-curl

Now after the installation completed you can check the PHP version with the command:

# php -v (‘v’ is in smallcase)

 

5) Install Nginx

Nginx, pronounced as “Engine X” and is a very fast and lightweight web server, that can be used to support static files, used as a reverse proxy and also for load balancing. It is one of the best Linux VPS Server as compared to Apache. It can handle higher load of HTTP request.

Firstly, update all the software packages by typing the following command:

# yum -y update

After that install EPEL repository that is required for Nginx packages by using command:

# yum -y install epel-release 

Now install  Nginx by typing the command:

 # yum -y install nginx

After the installation is completed you must Enable and Start Nginx server by typing command:

# systemctl start nginx

And enable it with the command:

# systemctl enable nginx

Also check its status with

# systemctl status nginx

6) Configure Firewall

After completed with installation part, configure the firewall settings with the following command:

Open HTTP port by typing command with:

# firewall-cmd –permanent –zone=public –add-service=http

If firewall package is not available then you can install it with command

 # yum -y install firewalld

And start firewalld service with command:

 # systemctl start firewalld

Now reload firewall configuration file by typing:

 # firewall-cmd –reload

Now verify your installation of Nginx by visiting the following URL on any browser you like with http://ip_address

7) Configure Nginx File

An Nginx server configuration file plays an important role, So you should be more careful when setting up this file.

For configuring Nginx file go inside the following path with the following command:

# cd /etc/nginx/conf.d

# vi default.conf

And write the following code in the above file i.e. default.conf.

Also change your domain in place of   ip_address   

server {

        listen       80;

        server_name  54.161.140.2;

root /usr/share/nginx/html/wordpress;

        index index.php index.html index.htm;

location / {

          try_files $uri $uri/ =404;

       }

       error_page 404 /404.html;

            location = /40x.html {

        root /usr/share/nginx/html/wordpress;

     }

        error_page 500 502 503 504 /50x.html;

            location = /50x.html {

        root /usr/share/nginx/html/wordpress;

}

        location ~* \.php$ {

        try_files $uri =404;

        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

        fastcgi_index index.php;

        include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        }

}

And save it with :wq command, after that edit the configuration file of php-fpm with the following command:

 # vi /etc/php-fpm.d/www.conf

Open the file with above command and edit the following lines i.e.

user = nginx

group = nginx

Add new listen under listen  = 127.0.0.1:9000

listen = /var/run/php-fpm/php-fpm.sock

And also add

listen.owner = nginx

listen.group = nginx

Remove comment (;) from the above two lines and save it with :wq.

8) Install WordPress File

You can easily download WordPress archive file from the link I provided in this blog.
First go inside /tmp directory by typing below command:

# cd /tmp

Download the latest WordPress setup by using wget command

# wget https://wordpress.org/latest.tar.gz

And if wget command not work then you can download it with the following command

# yum -y install wget

Now extract the downloaded file using below command:

# tar xzvf latest.tar.gz

After that move wordpress directory in /var/www/html directory by using command:

# mv wordpress /usr/share/nginx/html

Also change the ownership of /var/www/html directory by using the following command

# sudo chown -R nginx: /usr/share/nginx/html

# chmod -R 755 /usr/share/nginx/html

 

9) Test WordPress

Now for testing the server of WordPress you should restart the server for that follow the command:

# nginx -t

(If the command shows ‘successfully’ message then the changes in file are correct and else the changes are wrong in the nginx configuration file.)

# systemctl restart php-fpm

# systemctl restart nginx

Then open any browser and type inside URL i.e http://ip_address/

After then configuration page i.e. http://ip_address/wp-admin/ is open and select language.

How to install WordPress with LEMP stack on CentOS 7 VPS.

CONCLUSION– After this installation, you will be able to create or manage blog in WordPress CMS.

Learn how to scale, manage, and optimize your applications with a SLB. Read our solution brief "Get More from Your Enterprise Network".

DOWNLOAD SOLUTION BRIEF

Get started with CloudMinister Today