02 February 2022

How To Install Wordpress On Centos 7 With LEMP Nginx MariaDB or Mysql PHP

In this blog post, I will cover how to install wordpress on Centos 7 with LEMP which stands for Linux, Nginx (engine x) and php. It is needed to configure appropriately to make the most power of them.

How To Install Wordpress On Centos 7 With LEMP

Setup And Configure LEMP On Centos 7

1. Establish an ssh connection with centos 7 servers using ssh client, the good one is putty, using username and password that should be created after getting root with a password.

2. Install Nginx. To do this, follow these steps :

a. Download Nginx signing key.

sudo wget http://nginx.org/keys/nginx_signing.key

b. Install Nginx signing key :

sudo rpm --import nginx_signing.key

c. Add nginx repo. There is two version of Nginx, stable and mainline. I use mainline.

sudo nano /etc/yum.repos.d/nginx.repo

Copy and paste below into nginx.repo :

[nginx] name=nginx repo baseurl= http://nginx.org/packages/mainline/centos/7.4/$basearch/ gpgcheck=1 enabled=1

d. Run the command

sudo yum install update sudo yum install upgrade sudo yum install nginx

e. Check nginx version by run the command

nginx -v

If you want to implement any other module that is not listed in nginx by default, compile Nginx from source is the solution.

f. Nginx list command line:

To start nginx :

sudo systemctl start nginx

To restart nginx :

sudo systemctl restart nginx

To stop nginx :

sudo systemctl stop nginx

To enable nginx :

sudo systemctl enable nginx

3. Install mariadb or mysql. Mariadb and or Mysql server, which one you prefer to install, must be installed to store the data. To work with a database from a command line, MySQL or MariaDB client is the solution.

3.1. Install mysql server and client :

  ● Download MySQL, available free at dev.mysql.com/downloads/repo/yum.

sudo wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

  ● Install MySQL.

sudo yum localinstall mysql57-community-release-el7-11.noarch.rpm

3.2. If you like mariadb server and client, follow these steps to install it :

  ● Create mariadb repo.

sudo nano /etc/yum.repos.d/mariadb.repo

  ● Copy and paste below into mariadb.repo.

[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos7-amd64 gpgkey= https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1

  ● Install mariadb

sudo yum install MariaDB-server MariaDB-client

4. Securing MySQL

To secure MariaDB or mysql installation, then run the command in terminal.

sudo mysql_secure_installation

For resetting the password options, choose "n" , to use the password used in first-time setup database. Then several options will appear, choose "y" is the best answer.

5. Install PHP.

PHP is one of the most programming language used by many bloggers. In fact, Wordpress is written in PHP, and is used by blogger around the world. On the net, many people will teach about any other programming language, and still use WordPress.

There are several options, how php can be implemented on centos 7. PHP 7.2 is the latest version of PHP, I think we should use it as it has more features than the older ones.

5.1. Install php 7.2 via yum provided by Webtatic

  ● Provide Webtatic yum repository by typing these lines in the command line :

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

  ● Install php-fpm to connect to database and nginx web server.

yum install php72w-fpm

5.2. Install php 7.3 using Remis RPM Repository

  ● Add remis rpm repository

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm

  ● Enable and Activate it

yum install yum-utils yum-config-manager --enable remi-php73

  ● Install php 7.3

sudo yum install php73-php-fpm sudo systemctl start php73-php-fpm sudo systemctl enable php73-php-fpm

  ● Check php version

php -v

  ● Edit the nginx configuration file, so that PHP can run on Nginx.

nano /etc/nginx/nginx.conf

Add this code below into the http block.

upstream php { server 127.0.0.1:9000; }

And

Add this code below into the server block.

location ~ \.php$ { #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini include fastcgi.conf; fastcgi_intercept_errors on; fastcgi_pass php; }

  ● Replace default root location with /var/www/html.

  ● Delete error page configuration.

  ● Create php file info.php and put it in the root folder of the web to check php configuration.

sudo nano /var/www/html/info.php

Copy and paste the following inside of info.php :

<?php phpinfo(); phpinfo(INFO_MODULES); ?>

  ● Navigate to my_ip_address/info.php. If all goes well, it will give useful information about PHP modules that have been installed, predefined variables system on given system and short info of configuration of the database.

For the security reason, do a change to your php.ini so that you have the code below inside of it :

"cgi.fix_pathinfo = 0;"

How To Install Wordpress On Centos 7 With LEMP

Install Wordpress

1. Download the latest version of Wordpress.

user01@srv01:~$ wget -c http://wordpress.org/latest.tar.gz

2. In order to extract the tar.gz file, use tar.

user01@srv01:~$ tar xzvf latest.tar.gz

3. Copy the files from the newly extracted wordpress directory to the nginx root directory. The -R tells the command to recursively copy all the directories.

user01@srv01:~$ sudo cp -R wordpress/* /var/www/html/

4. Run the chown command below to ensure that nginx owns all the files in the nginx root directory. The -R again denotes to recursively apply the change to directories.

user01@srv01:~$ sudo chown -R nginx:nginx /var/www/html/

5. The command chmod is short for "change mode," and you use it to change the permissions on files and directories.

user01@srv01:~$ sudo chmod -R 755 /var/www/html/

6. Connect to the mysql client using the root password we set earlier. This is the same mysql client that was installed earlier as part of the mysql-client package.

user01@srv01:~$ mysql -u root -p

7. Create the mySQL database to house your Wordpress installation.

mysql> CREATE DATABASE your_blog_name;

8. Next, create a database user which Wordpress will use to access the database. Best practice dictates that you create a dedicated user for each application.

mysql> CREATE USER wp_dbuser IDENTIFIED BY 's5cUr3_p455w0rd';

9. Now, with the database user created, grant it all privileges on your Wordpress database.

mysql> GRANT ALL PRIVILEGES ON your_blog_name.* TO 'wp_dbuser'@'localhost';

10. Use the FLUSH PRIVILEGES command to force the privileges to take effect now.

mysql> FLUSH PRIVILEGES;

11. Type exit to leave the mysql client.

mysql> exit;

12. If you went to http://your_server_address right now, you would likely continue to see the same Nginx Default Page. This is because the default Nginx config, when looking for the default page, chooses *.html before *.php, and so displays the index.html provided by Nginx before the index.php provided by Wordpress. You could delete the index.html, but we will simply rename it to index.orig.html.

user01@srv01:~$ sudo mv /var/www/html/ /var/www/html/index.orig.html

13. Make a copy of wp-config-sample.php and rename it to wp-config.php.

14. Now we are ready to begin the actual Wordpress installation. Put the database you have just created in wp-config.php.

define( 'DB_NAME', 'bmw' ); define( 'DB_USER', 'gomersi' ); define( 'DB_PASSWORD', 'Gjtk8392' );

15. When Wordpress can communicate with your database, using the information you provided, you will see a page like this.

How To Install Wordpress On Centos 7 With LEMP

16. Provide the information about your blog: the blog name, username, password, email address and whether you want search engines to index your site. Fill out the information and click "Install Wordpress."

17. When everything goes as planned, you will see the page below. Click "Log in" to log in, using the password you created on the previous step.

18. This takes you into the Wordpress Dashboard, which is where all your administrative functions are done in Wordpress.

19. If you click the Home Icon at the top of the page, it will take you to your blog. Click on it and take a look. It should look very similar to this.

How To Install Wordpress On Centos 7 With LEMP

How To Install Wordpress On Centos 7 With LEMP

We hope this article has been helpful in showing you how to install Wordpress on Centos 7 with LEMP. Wordpress is a powerful Web application and we hope we have shown you how to get it set up for your needs.

Comments are closed