How to Install WordPress with Nginx and PHP 7.4 on CentOS 7

This tutorial discusses how to install WordPress with the Nginx web server paired with PHP v7.4 and MariaDB database or more popularly abbreviated as LEMP (Linux Nginx MySQL/MariaDB PHP).

*0.Update System*

Update CentOS and install the EPEL repository.

[INPUT]

1 2 yum update -y yum install epel-release -y

*1.Install Nginx*

Install Nginx.

[INPUT]

1 yum install nginx -y

Enable and start the Nginx service.

[INPUT]

1 2 3 systemctl enable nginx systemctl start nginx systemctl status nginx

Nginx service status

*2.Install PHP 7.4*

Install yum-utils and REMI repository.

[INPUT]

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

Verify the results of installing the REMI repository, see the contents of the yum.repos.d directory.

[INPUT]

1 ls -l /etc/yum.repos.d

yum.repos.d directory

Enable REMI PHP7.4 repository.

[INPUT]

1 yum-config-manager –enable remi-php74

Install PHP 7.4 along with the required extensions.

[INPUT]

1 yum install php74-php php74-php-fpm php74-php-gd php74-php-json php74-php-mbstring php74-php-mysqlnd php74-php-xml php74-php-xmlrpc php74-php-opcache -y

Create a php symbolic link to php74 and check the installed PHP.

[INPUT]

1 2 ln -s /usr/bin/php74 /usr/bin/php php -v

Command php -v

Configure PHP-FPM.

[INPUT]

1 vi /etc/opt/remi/php74/php-fpm.d/www.conf

Change the options as below.

[INPUT]

1 2 3 4 5 6 7 8 9 10 … user = nginx … group = nginx … listen = /run/php74-fpm.sock … listen.owner = nginx listen.group = nginx listen.mode = 0660

Enable and start PHP-FPM service.

[INPUT]

1 2 3 systemctl enable php74-php-fpm systemctl start php74-php-fpm systemctl status php74-php-fpm

PHP-FPM service status

*3.Create Nginx Server Block*

Creating a server block configuration file, replace DOMAIN.COM with the domain name you are using.

[INPUT]

1 vi /etc/nginx/conf.d/DOMAIN.COM.conf

Block server configuration script.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 server {     listen 80;     server_name DOMAIN.COM www.DOMAIN.COM;     root /var/www/DOMAIN.COM;     index index.php index.html index.htm;       location / {         try_files $uri $uri/ /index.php?$query_string;     }       location ~ \.php$ {         try_files $fastcgi_script_name =404;         include fastcgi_params;         fastcgi_pass                   unix:/run/php74-fpm.sock;         fastcgi_index                  index.php;         fastcgi_param DOCUMENT_ROOT    $realpath_root;         fastcgi_param SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;     }       access_log /var/log/nginx/DOMAIN.COM.access.log;     error_log /var/log/nginx/DOMAIN.COM.error.log; }

Create root directory and info.php file.

[INPUT]

1 2 mkdir /var/www/DOMAIN.COM echo “” > /var/www/DOMAIN.COM/info.php

Test the configuration and restart the Nginx service.

[INPUT]

1 2 3 nginx -t systemctl restart nginx systemctl status nginx

Test whether Nginx is able to run PHP scripts by accessing info.php.

Browse *http://DOMAIN.COM/info.php*.

PHP Information

*4.Install MariaDB*

Create file MariaDB 10.4 repository.

[INPUT]

1 vi /etc/yum.repos.d/mariadb.repo

Script mariadb.repo.

[INPUT]

1 2 3 4 5 6 7 # MariaDB 10.4 CentOS repository list – created 2020-06-22 11:29 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.4/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1

Install MariaDB.

[INPUT]

1 yum install MariaDB-server MariaDB-client -y

Enable and start the MariaDB service.

[INPUT]

1 2 3 systemctl enable mariadb systemctl start mariadb systemctl status mariadb

MariaDB service status

Secure the installation of MariaDB.

[INPUT]

1 mysql_secure_installation

Answer the questions displayed.

[INPUT]

1 2 3 4 5 6 7 Enter current password for root (enter for none): ENTER Switch to unix_socket authentication [Y/n] y Change the root password? [Y/n] y Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y

Log in to MariaDB.

[INPUT]

1 mysql -u root -p

Creating database, user and password, and granting database access rights to user.

[INPUT]

1 2 3 4 create database DBNAME; create user ‘DBUSER’@’localhost’ identified by ‘DBPASS’; grant all privileges on DBNAME.* to ‘DBUSER’@’localhost’; flush privileges;

*5.Install WordPress*

Download the latest WordPress.

[INPUT]

1 curl -O https://wordpress.org/latest.tar.gz

Extract latest.tar.gz.

[INPUT]

1 tar xzvf latest.tar.gz

Copy the contents of the wordpress directory to the root directory.

[INPUT]

1 cp -Rv wordpress/* /var/www/DOMAIN.COM

Change owner and root directory permissions.

[INPUT]

1 2 chown -R nginx:nginx /var/www/DOMAIN.COM chmod -R 755 /var/www/DOMAIN.COM

Browse *http://DOMAIN.COM*.

1. Language selection, use *English (United States)*. Then *Continue*.

Choose Language

3. *Let’s go!*

Database information

5. Enter DBNAME, DBUSER, dan DBPASS. *Submit*. 6. Copy the configuration text that is displayed.

Script wp-config.php

8. Create file *wp-config.php* then paste the text that has been copied.

[INPUT]

1 vi /var/www/DOMAIN.COM/wp-config.php

9. *Run the installation*. 10. Enter *Site Title*, *Username*, *Password*, *Your Email*. *Install WordPress*.

Website information

12. WordPress has been installed. 13. Click *Log In* to log in to the dashboard.

WordPress installed

*6.Done*

Front page *http://DOMAIN.COM*.

WordPress site

Dashboard page *http://DOMAIN.COM/wp-admin*.

WordPress dashboard

Good luck 🙂

Leave a Reply

Your email address will not be published.