Install LAMP Stack on Rocky Linux 8

|
Last Updated:
|
|

This guide describes a step by step tutorial on how to install LAMP stack on Rocky Linux 8.

Installing LAMP Stack on Rocky Linux 8

LAMP stack is a group of opensource web development softwares;

Run system package update.

dnf update

Install Rocky Linux 8 Linux System

In this case, the first component of the LAMP stack is our Rocky Linux 8 Linux system. To install Rocky Linux 8, see our guide on how to install it on VirtualBox by following the link below;

Install Rocky Linux 8 on VirtualBox

Install Apache HTTP Server on Rocky Linux 8

Apache http server can be installed on Rocky Linux 8 as easily as running the command below;

dnf install httpd

Running Apache on Rocky Linux 8

Once the installation is done, you can start and enable Apache to run on system reboot by executing;

systemctl enable --now  httpd

To check the status;

systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-06-17 19:27:04 EAT; 1s ago
     Docs: man:httpd.service(8)
 Main PID: 5969 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 4938)
   Memory: 24.7M
   CGroup: /system.slice/httpd.service
           ├─5969 /usr/sbin/httpd -DFOREGROUND
           ├─5970 /usr/sbin/httpd -DFOREGROUND
           ├─5971 /usr/sbin/httpd -DFOREGROUND
           ├─5972 /usr/sbin/httpd -DFOREGROUND
           └─5973 /usr/sbin/httpd -DFOREGROUND

Jun 17 19:27:04 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Jun 17 19:27:04 localhost.localdomain httpd[5969]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set >
Jun 17 19:27:04 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Jun 17 19:27:04 localhost.localdomain httpd[5969]: Server configured, listening on: port 80

To verify if it is enabled to run on boot, run the command below. The output should enabled;

systemctl is-enabled httpd

Allow External Access to Apache on Firewall

To enable external access to Apache web server, you need to allow web traffic on FirewallD. If you are serving just HTTP traffic, just open port 80/tcp otherwise, open port 443/tcp

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

Testing Apache on Rocky Linux 8

To confirm that Apache is ready to server HTTP content, simply open your browser and enter the server IP address as http://Server.IP. You should land on Apache HTTP server test page.

Install LAMP Stack on Rocky Linux 8

Install MariaDB Database Server on Rocky Linux 8

The default Rocky Linux upstream repos provides MariaDB 10.3. To install the latest MariaDB on Rocky Linux, follow the link below;

Install MariaDB 10.x on Rocky Linux 8

mysql -V
mysql  Ver 15.1 Distrib 10.5.10-MariaDB, for Linux (x86_64) using readline 5.1

Once you have installed MariaDB server, start and enable it to run on system boot.

systemctl enable --now  mariadb

Next, run the security script to disable remote root login, remove test databases, remove anonymous user accounts, if not already done.

mysql_secure_installation

You can login to your MariaDB server and create your databases.

Install PHP on Rocky Linux 8

By default, the AppStream repos on Rocky Linux provides PHP 7.2, 7.3 and 7.4;

dnf module list php
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

Install PHP 7.2 on Rocky Linux 8

The PHP 7.2 modules is enabled by default. Thus to install PHP 7.2 and MySQL PHP 7.2 module on Rocky Linux 8, run the command:

dnf install php php-mysqlnd

To install PHP 7.3 Rocky Linux 8

Enable PHP 7.3 module on Rocky Linux 8

dnf module enable php:7.3

Install PHP 7.3 Rocky Linux 8

dnf install php php-mysqlnd

To install PHP 7.4 Rocky Linux 8

dnf module reset php
dnf module enable php:7.4
dnf install php php-mysqlnd

Install PHP 8.0 on Rocky Linux 8

Install PHP Remi Repository on Rocky Linux 8.

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

Reset PHP module;

dnf module reset php
dnf module enable php:remi-8.0
dnf install php php-mysqlnd

Install PHP Extensions on Rocky Linux 8

If you need to install other PHP extensions for your web applications, simply install by running;

dnf install php-EXTENSION

Replacing EXTENSION with your respective PHP module.

Testing PHP on Rocky Linux 8

You can test PHP to confirm that is working as required as well check the version and installed modules using the simple PHP info script.

cat > /var/www/html/test.php << EOL
<?php 
phpinfo(); 
?>
EOL

Save the file and exit the file.

Restart Apache

systemctl restart httpd

Navigate to the browser and enter the address, http://<server-IP>/test.php

Install LAMP Stack on Rocky Linux 8

There you go, your LAMP stack is ready for your web development tasks.

Be sure to remove PHP test page.

rm -rf /var/www/html/test.php

Related Tutorials

Install LAMP Stack on Ubuntu 20.04

Install LAMP Stack on CentOS 8

Install LAMP Stack with MariaDB 10 on Debian 10 Buster

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment