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.
1 2 | yum update -y yum install epel-release -y |
1.Install Nginx
Install Nginx.
1 | yum install nginx -y |
Enable and start the Nginx service.
1 2 3 | systemctl enable nginx systemctl start nginx systemctl status nginx |
2.Install PHP 7.4
Install yum-utils and REMI repository.
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.
1 | ls -l /etc/yum.repos.d |
Enable REMI PHP7.4 repository.
1 | yum-config-manager --enable remi-php74 |
Install PHP 7.4 along with the required extensions.
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.
1 2 | ln -s /usr/bin/php74 /usr/bin/php php -v |
Configure PHP-FPM.
1 | vi /etc/opt/remi/php74/php-fpm.d/www.conf |
Change the options as below.
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.
1 2 3 | systemctl enable php74-php-fpm systemctl start php74-php-fpm systemctl status php74-php-fpm |
3.Create Nginx Server Block
Creating a server block configuration file, replace DOMAIN.COM with the domain name you are using.
1 | vi /etc/nginx/conf.d/DOMAIN.COM.conf |
Block server configuration script.
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.
1 2 | mkdir /var/www/DOMAIN.COM echo "<?php phpinfo(); ?>" > /var/www/DOMAIN.COM/info.php |
Test the configuration and restart the Nginx service.
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.
4.Install MariaDB
Create file MariaDB 10.4 repository.
1 | vi /etc/yum.repos.d/mariadb.repo |
Script mariadb.repo.
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.
1 | yum install MariaDB-server MariaDB-client -y |
Enable and start the MariaDB service.
1 2 3 | systemctl enable mariadb systemctl start mariadb systemctl status mariadb |
Secure the installation of MariaDB.
1 | mysql_secure_installation |
Answer the questions displayed.
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.
1 | mysql -u root -p |
Creating database, user and password, and granting database access rights to user.
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.
1 | curl -O https://wordpress.org/latest.tar.gz |
Extract latest.tar.gz.
1 | tar xzvf latest.tar.gz |
Copy the contents of the wordpress directory to the root directory.
1 | cp -Rv wordpress/* /var/www/DOMAIN.COM |
Change owner and root directory permissions.
1 2 | chown -R nginx:nginx /var/www/DOMAIN.COM chmod -R 755 /var/www/DOMAIN.COM |
Browse http://DOMAIN.COM.
- Language selection, use English (United States). Then Continue.
- Let’s go!
- Enter DBNAME, DBUSER, dan DBPASS. Submit.
- Copy the configuration text that is displayed.
- Create file wp-config.php then paste the text that has been copied.1vi /var/www/DOMAIN.COM/wp-config.php
- Run the installation.
- Enter Site Title, Username, Password, Your Email. Install WordPress.
- WordPress has been installed.
- Click Log In to log in to the dashboard.
6.Done
Front page http://DOMAIN.COM.
Dashboard page http://DOMAIN.COM/wp-admin.
If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!
Donate via PayPal: https://paypal.me/musaamin
Hello,
Thanks for the tutorial it works.
I now needs help to make the site loads via https, please do a tutorial on this too.
Thanks
Install certbot nginx
sudo yum install certbot-nginx
. request Let’s Encrypt SSLsudo certbot --nginx -d example.com -d www.example.com