Install LAMP Stack on Rocky Linux 9 {Step by Step}

LAMP is a popular stack in software development that combines various software technologies to create a platform for both static and dynamic web applications. Developers love LAMP for its ease of deployment and customization. It was introduced by Michael Kunze in 1998, and its acronym stands for Linux, Apache, MySQL (or MariaDB), and PHP. LAMP architecture is widely used in the web industry, particularly with CMS systems like WordPress, Joomla, Drupal, and Magento.

If you're looking to install and configure LAMP on Rocky Linux 9, this guide can help you  in 3 simple steps. These steps can also be used for other versions of Rocky, RHEL, Alama, and Fedora with a few modifications to the installation methods.

Prerequisites :

Operating System       :    Rocky Linux / RHEL /Alama /Fedora
Packages & Dependencies:    Apache/Nginx Webserver and Standalone Databases like MySQL/MariaDB and PHP
User account           :    root user or user account with sudo privileges
Recommended to run all the administrative commands as with sudo privilege instead of root.

Here is the complete installation guide for Rocky Linux 9.1

Here's a complete  step-by-step guide to configuring sudo users:

My Lab Setup :

Operating System    :   Rocky Linux  release 9.1 (Blue Onyx)
Hostname            :
IP Address          :
Step 1: Install Apache Package


To initiate the LAMP stack, we need to install the Apache package, but we recommend that it is always to update the Operating system prior to the installation of the Apache package.

$ sudo dnf update -y

Once your OS is updated, you can start the process of installing the Apache "httpd" Web Server Package from the Rocky App stream by using the following command in your terminal. While writing this article, we used version 2.4.53 of httpd.

$ sudo dnf install httpd



You must start the httpd service after installing the Apache Web Server package.

$ sudo systemctl start httpd           --> This is used to start the httpd daemon.


$ sudo systemctl enable httpd          --> Used start the apache service during reboot.


$ sudo systemctl status httpd            -->  Used to verify the status of Apache Server                                                                             (Active  or Disabled)



From the above output we can see that our newly installed apache service is active and running.

You will now have to run the following command in order to open up the firewall port for HTTP (80) as well as HTTPS (443) services. As soon as the ports are open, the public will be able to access our website.

$ sudo firewall-cmd --permanent --add-port=80/tcp


$ sudo firewall-cmd --permanent --add-port=443/tcp


$ sudo firewall-cmd --reload


The following command displays all the information available in the default zone file. If you would like to learn more about the firewalld service, check out this article 15 useful firewall-cmd commands for Linux.

$ sudo firewall-cmd --list-all



That's it, you can now verify and confirm that the installed Apache service is by active and running. To do so, open your browser and enter your IP address on your server. For example, my IP address is "", just hit the enter key and you will see the Apache Test Page as shown in the screenshot below. This means that your Server is up and running.


Step 2: Install MySQL / MariaDB Server


The next step is to install the 2nd component of LAMP, which is the MySQL/MariaDB database. The demo will use MariaDB as it is a fast, scalable, and reliable database, but you can also use MySQL. You can install MariaDB by running this command. The available version of MariaDB on Rocky Linux 9.1 is 10.15.

$ sudo dnf install mariadb-server mariadb -y


Upon completion of the installation, run the following command to start MariaDB on every reboot.

$ sudo systemctl start mariadb


$ sudo systemctl enable mariadb


$ sudo systemctl status mariadb

Check-MariaDB-Server-Status- on-Rocky-Linux


Based on the output above, we can see that our newly installed Mariadb service is active and running.

By default, MariaDB comes with settings that aren't suitable for production, including security levels. As a result, we need to take additional steps to strengthen security.

You can use one of the following commands to execute the MySQL/MariaDB Secure Installation Script.

$  sudo mariadb-secure-installation      or           $ sudo mysql_secure_installation

The screenshot below shows the instructions for beginners so they can understand them easily:


Since it's a fresh installation, there's no root password to set, so simply hit enter to move on. The remaining steps can be completed by typing "Y", which will remove the anonymous user, block the root user from logging in, and remove the test database.


Switch to unix_socket authentication


That's it. We have now completely updated the MaraiDB Security Measurements. For testing purposes, you can simply use the following command to login to MariaDB server.

$ mysql -u root -p

mysql -u root -p-on-Rocky-Linux

Once you have successfully logged-in, you will see the MariaDB prompt. Type "quit" to exit.

Step 3: Install PHP


Next, we will install PHP, which is the third component. PHP is short for Hypertext Preprocessor. Thousands of dynamic sites and apps use PHP. Before attempting to install PHP, we can check the available PHP versions in Rocky Linux 9.1. Use the following command to check the version.

$ sudo dnf module list php

dnf module list php-on-Rocky-Linux

This output indicates that Rocky Linux 9.1 includes the PHP 8.1 version as the default PHP stream. You can now activate PHP 8.1 using the following command:

$ sudo dnf module enable php:8.1

sudo dnf module enable php%3A8.1-on-Rocky-Linux

Using the same command as before, "sudo dnf module list php", you should now see php version 8.1 is enabled.

dnf module list php-on-Rocky-Linux


The following command install PHP easily and also install the dependencies of several PHP modules along with the main PHP package.

$ sudo dnf install php php-cli php-gd php-curl php-zip php-mbstring php-mysqlnd -y

sudo dnf install php-on-Rocky-Linux

To verify the PHP version, run the following command:

$ php -v


Last but not least, the Apache Web Server needs to be restarted, so that PHP requests can be processed.

$ sudo systemctl restart httpd


PHP can be tested in a web browser by creating a file named "info.php". Here is an overview of what the sample configuration file looks like in the form of tables. The "info.php" should be placed in the Document Root of Apache (/var/www/html).

$ sudo vi /var/www/html/info.php



Save and close the file. Open your web browser and enter 'http://youripaddress/info.php'. The screenshot below shows PHP information.


Once your debugging is complete, it is highly recommended to delete "info.php" file from your server as it may pose a huge security risk to unauthorized users.

$ sudo rm -f /var/www/html/info.php


That's it. We hope this article has helped you understand installing LAMP stack on Rocky Linux 9.1. Drop me your feedback/comments. Feel free to share this article with others if you like it.

Also, handling multiple databases in the command line is a tedious task. To overcome this situation most of them used the GUI tools, here we recommend an opensource tool called PhpMyAdmin. Here is the step-by-step guide on how to install PhpMyAdmin on Rocky Linux.

Support My Work

Thank you for your support and for being a part of my journey, I would be very grateful if you could consider buying me a coffee. The contributions you make will help me to continue to produce quality content and enhance my readers' experience.

Buy Me A Coffee

Thank you for your endless support!


About John Gomez

John Britto Founder & Cheif-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 10+ years of experience in Linux and Open Source technologies.

View all posts by John Gomez →

Leave a Reply

Your email address will not be published.