How to Install LAMP on Rocky Linux

Install LAMP on Rocky Linux

In this tutorial, we will guide you on how to Install LAMP on Rocky Linux. LAMP is a bundle of software tools. The full form of the LAMP is Linux, Apache, MariaDB/MySQL And PHP all are open-source tools and easy to use.

Rocky Linux is an open-source operating system. It will be designed to be bug-free and compatible with the Red Hat Enterprise Linux (RHEL). Rocky Linux is an adequate replacement for CentOS distributions. Rocky Linux is more stable, efficient, and performs compared to centos.

Install LAMP Stack on Rocky Linux

In this tutorial, We will read how to install and configure the LAMP on Rocky Linux.

Step 1. Installing Apache on Rocky Linux

Apache package is already there in Rocky repositories, So we just need to install the package by running the below commands:

dnf update
dnf install httpd

After the run installation command. We will see the output something like this.

Installing Apache on Rocky Linux
linuxpanda.com

After that, enable the httpd web server on Rocky Linux.

 sudo systemctl enable httpd

And, then start the httpd web server service using the below command.

sudo systemctl start httpd

Now check the httpd is running on Rocky Linux.

systemctl status httpd
HTTP and HTTPS traffic
Linuxpanda.com

Now Next, add new firewall rules to allow HTTP and HTTPS traffic, and open port 80 on the server.

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --permanent --zone=public --add-port=80/tcp

Now Restart and permanently add the firewall.

firewall-cmd --reload
firewall-cmd --permanent --list-all

Now we can test that the Apache installation is right by visiting the Server IP address.

http://server-IP
HTTP Server Test
Linuxpanda.com

Step 2. Install MariaDB on Rocky Linux

Now we install MariaDB. MariaDB is available in Rocky Linux repositories by default, so we can install it with the following command.

sudo dnf install mariadb-server mariadb
mariadb-server IP
linuxpanda.com

After the installation of MariaDB, Now start and enable the MariaDB service.

sudo systemctl enable --now mariadb
sudo systemctl start mariadb

Now confirm the MariaDB service is running using the below command.

sudo systemctl status mariadb
sudo systemctl status mariadb
linuxpanda.com

After the successful installation of MariaDB, Then next step is to Secure the MariaDB installation and set the new root password for the database server.

sudo mysql_secure_installation

After the run command, the first step is to set the new strong root password. Now set the password and the database server is now fully configured and secure.

Now, run MariaDB and login as root.

mysql -u root
mysql -u root
linuxpanda.com

Step 3. Install PHP on Rocky Linux

Now the final step is to install the PHP. Rocky Linux provides multiple PHP versions. We can check the available version using the following command.

sudo dnf module list php

The list of available modules.

sudo dnf module list php
linuxpanda.com

Now we will install PHP 8.1 as shown.

dnf module install php:8.1
module install php:8.1
linuxpanda.com

Now we install the required PHP extensions, Using the following command.

dnf install php-mysqlnd php-gd php-intl

Once all are installed, Now check the PHP version using the below command.

php -v
php -v
linuxpanda.com

Now test PHP functionality with Apache by creating the PHP default page.

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

Add the following line of code to the info.php file.

<?php

phpinfo();

?>

Save the info.php file and restart the Apache service.

sudo systemctl restart httpd

Now Search the following URL in the web browser. And the default PHP page will be shown.

http://server-ip/info.php
erver-ip/info.php
linuxpanda.com

Conclusion

In this article, We have learned about how to install the LAMP on a Rocky Linux server. Rocky Linux is compatible with RHEL. If you are looking for a stable and compatible OS that Rocky Linux is the best option to use for multiple reasons.

If you guys face any issues then mention your queries in the comment section.