How to Install LAMP Stack on Rocky Linux 8

Channel: Linux
Abstract: Apache is a completely free and open-source web server. Apache webserver can be configured to serve PHP pages. The current default version available o

LAMP stack is a free and open-source development stack that is used by developers and hosting companies in hosting web applications. It's an acronym for Linux Apache MariaDB ( or MySQL) & PHP. LAMP comprises 3 components: the Apache web server, the MariaDB database, and PHP - a popular server-side scripting language.

In this tutorial, we learn how to install LAMP stack on Rocky Linux 8 using DNF. DNF is the default package manager in Rocky Linux. This installation has Apache 2.4, MariaDB 10.3, and PHP 8.0.

Step 1: Install Apache web server

Before starting, it's good to update all software packages on Rocky Linux 8.

Install WordPress On XAMPP | Create...

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

Install WordPress On XAMPP | Create A Offline WordPress Website | PROWEBTIPS
$ sudo dnf upgrade

Developed by Apache Foundation, Apache is a completely free and open-source web server. Apache webserver can be configured to serve PHP pages.

The current default version available on Rocky Linux is Apache 2.4.

To install Apache web server, type:

$ sudo dnf install httpd

This installs Apache alongside other dependencies that will be needed by the Apache webserver.

After the installation is done, enable Apache to start automatically on boot time as follows:

$ sudo systemctl enable httpd

Next, proceed and start the Apache webserver with the command:

$ sudo systemctl start httpd

To verify the status of the apache server run:

$ sudo systemctl status httpd
Apache service status

If you have enabled firewalld firewall, then we need to allow external access to your web server.

To allow HTTP and HTTPS traffic (in case you want to encrypt the webserver with SSL ) on the firewall.

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

To make the changes effective, reload the firewall service:

$ sudo firewall-cmd --reload

You can verify by listing the current firewall settings:

$ sudo firewall-cmd --permanent --list-all

Output:

public
   target: default
   icmp-block-inversion: no
   interfaces:
   sources:
   services: cockpit dhcpv6-client http https ssh
   ports:
   protocols:
   masquerade: no
   forward-ports:
   source-ports:
   icmp-blocks:
   rich rules:

Another nifty way to check if the webserver is functional is to browse the server's IP.

http://server-IP or domain name

This will display the Apache Test Page.

Apache webserver test page Step 2: Install PHP 8 on Rocky Linux 8

Next, we are going to install PHP. At the time of writing this guide, the latest version is PHP 8.0. However, Rocky Linux AppStream repositories only provide PHP 7.4 as the latest version.

To install the latest PHP release, first enable the Remi repository. But before that, enable the EPEL repository first.

$ sudo  dnf install epel-release

Then install the Remi repository.

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

To list the available PHP module, type:

$ sudo dnf module list php
DNF List PHP Modules

Once Remi is installed, reset the PHP module and enable the latest Remi PHP module which is Remi-8.0.

$ sudo dnf module list reset php
$ sudo dnf module enable php:remi-8.0

Next, install PHP:

$ sudo dnf install php

Once the installation is complete, run the following command to verify the version of PHP installed.

$ php  -v
Check PHP version in Rocky

At this time of writing this guide, this installed PHP 8.0.8.

If PHP 7.4 is your desired version you can install it from Rocky Linux AppStream by simply running the command dnf module install php:7.4. As of now, the default PHP stream is PHP 7.2.

Another way to test PHP is to create a simple PHP file in the default webroot directory of Apache.

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

Paste the lines of code into the file.

<?php

phpinfo();

?>

Save and exit the file. Then restart the Apache webserver.

$ sudo systemctl restart httpd

Then navigate to the following URL. This will display detailed information about the PHP version installed plus information regarding other PHP extensions.

http://server-ip/info.php
PHP Test Page Step 3: Install MariaDB database Server

MariaDB is a fork of MySQL. It is an alternative for MySQL. The MariaDB database is now widely accepted because of its speed and added features.

The current default version available on Rocky Linux 8 AppStream is MariaDB 10.3.

To install MariaDB, run the following command.

$ sudo dnf install mariadb-server mariadb

After installing MariaDB, enable MariaDB to start automatically on boot time as follows:

$ sudo systemctl enable mariadb

Next, proceed and start the MariaDB with the command:

$ sudo systemctl start mariadb

Now, we can verify the status of MariaDB as follows:

$ sudo systemctl status mariadb
Check MariaDB server status

From the output, we can see that MariaDB is up and running. Lastly, we need to secure the MariaDB database server since the default settings are weak and present a security risk. Therefore run the MySQL script below to harden the database server.

$ sudo mysql_secure_installation

Set the Root password.

Set Root password MariaDB

Then press 'Y' for the remaining prompts.

Harden MariaDB using mysql_secure_installation script

To log in to MariaDB, simply run:

$ sudo mysql -u root -p
Log in to MariaDB Conclusion

That was a walkthrough of the installation of the LAMP stack on Rocky Linux 8. The installation is quite simple and straightforward. As you have noted, the procedure mirrors the one of installing LAMP on CentOS 8 since Rocky Linux is a fork of CentOS 8.

Ref From: linoxide

Related articles