How to Install LAMP Stack on Rocky Linux

In today’s blog we will know how to install LAMP stack on rocky linux. In the development community, LAMP is a well-liked stack for hosting both static and dynamic websites. It stands for PHP, MySQL (or MariaDB), Apache, and Linux. Notably, it includes PHP, MySQL or MariaDB, and the Apache web server.

Pre-requisite

Make sure you have an instance of Rocky Linux 8 with a sudo user configured. If you need any support in OS installation refer How to Install Rocky Linux 8

Now lets start with the Installation

Installation of Apache

We will begin installing the Apache webserver as the first component. The httpd software package offers this. After installation, the httpd daemon waits for incoming HTTP requests from client devices in the background.

$ sudo dnf install httpd -y 

Allow the HTTP traffic in the Firewall services

$ sudo firewall-cmd  --permanent --zone=public --add-service=http 
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo firewall-cmd --reload

Enable and start the service

$ sudo systemctl enable httpd
$ sudo systemctl start httpd

Install MariaDB

Installing a database server comes next. We will go with MariaDB over MySQL although you are free to use any one of them. Because MariaDB has so many improvements over MySQL, including safer and quicker replication, several high-performance storage engines, backward compatibility, and improved overall speed, we will concentrate on it.

$ sudo dnf install mariadb-server mariadb -y

Enable and start the DB services

$ sudo systemctl enable --now mariadb
$ sudo systemctl start mariadb

Let us harden our database to get away with the default settings

$ sudo mysql_secure_installation

A text-based wizard will ask you to set a root password for MariaDB along with removing empty databases, restricting remote access except for localhost, removing anonymous users, and more.

In order to set a root password, hit ‘Y’ after pressing ENTER, as there isn’t one set by default. Give a strong password and make sure it’s correct.

For the remaining settings, type ‘Y’. In addition to blocking remote root login and eliminating the Test database, which is superfluous in a production setting, this will successfully delete or purge any anonymous users.

Install PHP

PHP will be the final component to be installed. The programming language PHP, which stands for PHP Hypertext Preprocessor, is used to create dynamic webpages.

There can be multiple version available so let us check the versions available

$ sudo dnf module list php

This provides a list of PHP modules and Streams. To install the latest module Stream from the repository, reset the PHP streams.

$ sudo dnf module reset php

Now enable the preferred PHP stream

$ sudo dnf module install php:7.4

We can also install the additional PHP extensions

$ sudo dnf install php-curl php-zip -y

Once installed you can check the versions

$ php -v

Test LAMP Stack PHP in browser

Create the file

sudo vim /var/www/html/info.php

Add the following line in the info.php file we have created using the above command:

<?php
phpinfo ();
?>

Save and exit the file.

Restart the Web Server

$ sudo systemctl start httpd

Hit the below URL in the browser of your choice

http://your-server-ipaddress/info.php

A page displaying the PHP version among other parameters such as details of PHP extensions enabled will be displayed.

Conclusion

In this article we have successfully installed the LAMP Stack on Rocky Linux which is an acronym for Linux, Apache, MySQL and PHP software stack. This combination of software pieces are open-source and they are used together to build powerful web applications and websites. You can now start testing and hosting your web applications. We will also use this article further in any of our blogs where we require to have a LAMP stack as pre-requisite for any applications or programs. Refer LAMP (software bundle) for more details

Leave a comment