Install LEMP Stack on Rocky Linux 8

|
Last Updated:
|
|

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 update

Install 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 nginx

Running 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  nginx

To 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 nginx

Allow 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 --reload

Testing 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.

rocky linux

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 -V
mysql  Ver 15.1 Distrib 10.5.10-MariaDB, for Linux (x86_64) using readline 5.1

Once you have installed MariaDB server, start and enable it to run on system boot.

systemctl enable --now  mariadb

Next, run the security script to disable remote root login, remove test databases, remove anonymous user accounts, if not already done.

mysql_secure_installation

You 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 php
Rocky 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-mysqlnd

To install PHP 7.3 Rocky Linux 8

Enable PHP 7.3 module on Rocky Linux 8

dnf module enable php:7.3

Install PHP 7.3 Rocky Linux 8

dnf install php php-mysqlnd

To install PHP 7.4 Rocky Linux 8

dnf module reset php
dnf module enable php:7.4
dnf install php php-mysqlnd

Install PHP 8.0 on Rocky Linux 8

Install PHP Remi Repository on Rocky Linux 8.

dnf install epel-release
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Reset PHP module;

dnf module reset php
dnf module enable php:remi-8.0
dnf install php php-mysqlnd

Install 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-EXTENSION

Replacing 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(); 
?>
EOL

Save the file and exit the file.

Restart Nginx

systemctl restart nginx

Navigate to the browser and enter the address, http://<server-IP>/test.php

php 7.4 rocy

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

Other Tutorials

Install LAMP Stack on Rocky Linux 8

Install Vtiger CRM on Rocky Linux 8

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment