How to Install LAMP Stack on Rocky Linux 8

Install LAMP Stack on Rocky Linux 8

In this article, we will have explained the necessary steps to install LAMP Stack on Rocky Linux 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

LAMP is an acronym for Linux, Apache, MySQL (or MariaDB) & PHP. Notably, it comprises the Apache web server, MySQL or MariaDB database server, and PHP. This combination of software pieces is open-source and they are used together to build powerful web applications and websites.

Install LAMP Stack on Rocky Linux 8

Step 1. First, before you start installing any package on your Rocky Linux server, we always recommend making sure that all system packages are updated.

sudo dnf install epel-release
sudo dnf update
sudo dnf upgrade

Step 2. Install Apache Web Server.

Run the following command to install Apache HTTPd webserver on Rocky Linux 8:

sudo dnf install httpd httpd-tools

Once the installation is complete, enable Apache (to start automatically upon system boot), start the webserver, and verify the status using the commands below:

systemctl enable httpd
systemctl start httpd
systemctl status httpd

If the firewall is enabled consider allowing HTTP and HTTPS services:

sudo firewall-cmd --permanent --add-service={http,https}
sudo firewall-cmd --reload

Next, open your web browser and verify the Apache test page using the URL http://your-server-ip. You should see the Apache test page on the following screen:

Install LAMP Stack on Rocky Linux 8

Step 3. Install MariaDB Server.

The default Rocky Linux upstream Repos provides MariaDB 10.7. To install the latest MariaDB on Rocky Linux, follow the link below:

sudo dnf install mariadb-server mariadb

Once installed, start and enable MariaDB on boot time as shown:

systemctl start mariadb
systemctl enable mariadb

MariaDB server package comes with a script called mysql_secure_installation performs several security-related operations, and sets the root password:

sudo mysql_secure_installation

Install LAMP Stack on Rocky Linux 8

Step 4. Install PHP.

By default, the AppStream Repos on Rocky Linux provide PHP 7.2, 7.3, and 7.4:

sudo dnf module list php

Result:

Last metadata expiration check: 0:02:46 ago on Wednesday 14 Sep 2021 18:23:28 AM UTC.
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

The default PHP version is set to PHP 7.2. If you want to install the latest PHP 7.4, you will need to reset the default PHP steams:

sudo dnf module reset php

Enable PHP 7.4 module on Rocky Linux 8:

sudo dnf module enable php:7.4

After that, install PHP 7.4 with other extensions using the following command:

sudo dnf install php php-cli php-curl php-zip php-mysqli

To confirm PHP is installed, run the command:

php -v

Step 5. Testing PHP on Rocky Linux 8.

To do so, create an info.php file:

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

Add the following lines:

<?php
phpinfo();
?>

Save and close the file, then restart the Apache service to apply the changes:

systemctl restart httpd

Finally, head over to your browser and browse the URL below:

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

That’s all you need to do to install LAMP on Rocky Linux. I hope you find this quick tip helpful. For further reading on the LAMP Stack, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.