How to Install WordPress with LEMP (Nginx, MariaDB, and PHP) on Rocky Linux 8 ?

LEMP is an open-source software stack and is and ideally suited to hosting web applications on the internet. LEMP is an acronym for Linux, Nginx, MariaDB/MySQL, and PHP. Generally, LEMP stacks are used to host high-traffic and highly scalable websites on the internet. A LEMP stack is a group of open-source Linux-based software including Nginx web server, MariaDB database server, and PHP.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related LEMP queries.

In this context, we shall look into how to install a LEMP stack on Rocky Linux 8.


Steps to Install LEMP stack on Rocky Linux 8

1. Perform System Update

Once you are logged in to your server via an ssh tool such as putty, run the following command to update your base system with the latest available packages:

$ dnf update -y


2. Install Nginx Web Server on Rocky Linux 8

Here, you will need to do is to install the Nginx web server package on your system. You can install it using the following command:

$ dnf install nginx -y

This will install the Nginx package along with other required dependencies to your system. Next, start the Nginx service and enable it to start at system reboot:

$ systemctl start nginx
$ systemctl enable nginx

You can now verify the status of the Nginx service using the following command:

$ systemctl status nginx

You can also verify the Nginx installation through the web browser. Open your web browser and type the URL http://your-server-ip. You should see the Nginx test page.


3. Install MariaDB Database Server on Rocky Linux 8

Next, you will need to install the MariaDB or MySQL database server on your system. We would recommend installing the MariaDB server due to its numerous enhancements, like high-performance storage engines and backward compatibility with MySQL.

Run the following command to install the MariaDB server:

$ dnf install mariadb-server -y

After installing MariaDB, start the MariaDB service and enable it to start at system reboot:

$ systemctl start mariadb
$ systemctl enable mariadb

Run the following command to verify that the MariaDB daemon is running:

$ systemctl status mariadb

Next, We would recommend running the mysql_secure_installation script to secure the MariaDB installation.

You can run it using the following command:

$ mysql_secure_installation

You will then be asked whether to set a MariaDB root password, remove anonymous users, disallow root login, and remove the test database:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
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


4. Install PHP on Rocky Linux 8

Next, you will need to install PHP on your system. By default, Rocky Linux AppStream repo provides multiple versions of PHP.

You can check all available PHP versions using the following command:

$ dnf module list php

The default PHP version is set to PHP 7.2. If you want to install the latest PHP 7.4, you will need to reset the default PHP steams.

Run the following command to reset the default PHP:

$ dnf module reset php

Next, enable the PHP 7.4 version using the following command:

$ dnf module enable php:7.4

Next, install PHP 7.4 with other extensions using the following command:

$ dnf install php php-fpm php-cli php-curl php-zip php-mysqli -y

Once PHP is installed, verify the installed version of PHP with the following command:

$ php -v

You should see the following:

PHP 7.4.6 (cli) (built: May 12 2020 08:09:15) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies

By default, PHP-FPM runs as the apache user, so you will need to edit the PHP-FPM configuration file and set it to run as the nginx user:

$ nano /etc/php-fpm.d/www.conf

Change the following lines:

user = nginx
Group = nginx

Save and close the file when you are finished.

Another way to test the PHP version is to create an info.php file in the Nginx web root directory and access it through the web browser.

First, create an info.php file:

$ nano /usr/share/nginx/html/info.php

Add the following lines:

<?php
phpinfo();
?>

Save and close the file, then restart the Nginx and PHP-FPM service to apply the changes:

$ systemctl restart nginx php-fpm

Now, open your web browser and access the info.php page using the URL http://your-server-ip/info.php. You should see the PHP version on the screen.


[Need help in fixing Nginx configuration issues ? We can help you. ]

This article covers how to install the LEMP stack on Rocky Linux 8. In fact, The terminology LEMP is an acronym for Linux, Nginx (pronounced as Engine X, hence the E) which is a web browser, MariaDB or MySQL – database, and PHP for processing dynamic content). LEMP stack is popularly used for hosting high-traffic and highly scalable web applications and websites.

Related Posts