This guide describes a step by step tutorial on how to install LEMP stack on Rocky Linux 8.
LEMP stack is a group of opensource web development softwares;
- Linux OS, Rocky Linux 8, in this case.
- Nginx HTTP server,
- MariaDB/MySQL relational database management systems
- PHP web scripting language
Installing LEMP Stack on Rocky Linux 8
Run system package update.
dnf updateInstall Rocky Linux 8 Linux System
In this case, the first component of the LEMP stack is our Rocky Linux 8 Linux system. To install Rocky Linux 8, see our guide on how to install it on VirtualBox by following the link below;
Install Rocky Linux 8 on VirtualBox
Install Nginx HTTP Server on Rocky Linux 8
Nginx http server can be installed on Rocky Linux 8 as easily as running the command below;
dnf install nginxRunning Nginx on Rocky Linux 8
Once the installation is done, you can start and enable Nginx to run on system reboot by executing;
systemctl enable --now  nginxTo check the status;
systemctl status nginx● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/nginx.service.d
           └─php-fpm.conf
   Active: active (running) since Sat 2021-06-19 00:13:03 EAT; 8s ago
  Process: 51988 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 51987 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 51985 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 51990 (nginx)
    Tasks: 2 (limit: 11391)
   Memory: 4.0M
   CGroup: /system.slice/nginx.service
           ├─51990 nginx: master process /usr/sbin/nginx
           └─51991 nginx: worker process
Jun 19 00:13:03 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jun 19 00:13:03 localhost.localdomain nginx[51987]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jun 19 00:13:03 localhost.localdomain nginx[51987]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jun 19 00:13:03 localhost.localdomain systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jun 19 00:13:03 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.
To verify if it is enabled to run on boot, run the command below. The output should enabled;
systemctl is-enabled nginxAllow External Access to Nginx on Firewall
To enable external access to Nginx web server, you need to allow web traffic on FirewallD. If you are serving just HTTP traffic, just open port 80/tcp otherwise, open port 443/tcp
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reloadTesting Nginx on Rocky Linux 8
To confirm that Nginx is ready to server HTTP content, simply open your browser and enter the server IP address as http://Server.IP. You should land on Nginx HTTP server test page.

Install MariaDB Database Server on Rocky Linux 8
The default Rocky Linux upstream repos provides MariaDB 10.3. To install the latest MariaDB on Rocky Linux, follow the link below;
Install MariaDB 10.x on Rocky Linux 8
mysql -Vmysql  Ver 15.1 Distrib 10.5.10-MariaDB, for Linux (x86_64) using readline 5.1Once you have installed MariaDB server, start and enable it to run on system boot.
systemctl enable --now  mariadbNext, run the security script to disable remote root login, remove test databases, remove anonymous user accounts, if not already done.
mysql_secure_installationYou can login to your MariaDB server and create your databases.
Install PHP on Rocky Linux 8
By default, the AppStream repos on Rocky Linux provides PHP 7.2, 7.3 and 7.4;
dnf module list phpRocky Linux 8 - AppStream
Name                             Stream                              Profiles                                              Summary                                          
php                              7.2 [d]                             common [d], devel, minimal                            PHP scripting language                           
php                              7.3                                 common [d], devel, minimal                            PHP scripting language                           
php                              7.4                                 common [d], devel, minimal                            PHP scripting language
Install PHP 7.2 on Rocky Linux 8
The PHP 7.2 modules is enabled by default. Thus to install PHP 7.2 and MySQL PHP 7.2 module on Rocky Linux 8, run the command:
dnf install php php-mysqlndTo install PHP 7.3 Rocky Linux 8
Enable PHP 7.3 module on Rocky Linux 8
dnf module enable php:7.3Install PHP 7.3 Rocky Linux 8
dnf install php php-mysqlndTo install PHP 7.4 Rocky Linux 8
dnf module reset php
dnf module enable php:7.4dnf install php php-mysqlndInstall PHP 8.0 on Rocky Linux 8
Install PHP Remi Repository on Rocky Linux 8.
dnf install epel-releasednf install https://rpms.remirepo.net/enterprise/remi-release-8.rpmReset PHP module;
dnf module reset phpdnf module enable php:remi-8.0dnf install php php-mysqlndInstall PHP Extensions on Rocky Linux 8
If you need to install other PHP extensions for your web applications, simply install by running;
dnf install php-EXTENSIONReplacing EXTENSION with your respective PHP module.
Testing PHP on Rocky Linux 8
You can test PHP to confirm that is working as required as well check the version and installed modules using the simple PHP info script.
cat > /usr/share/nginx/html/test.php << EOL
<?php 
phpinfo(); 
?>
EOLSave the file and exit the file.
Restart Nginx
systemctl restart nginxNavigate to the browser and enter the address, http://<server-IP>/test.php

There you go, your LEMP stack is ready for your web development tasks.
Be sure to remove PHP test page.
rm -rf /usr/share/nginx/html/test.php 
					