How to Install LAMP Stack on Rocky Linux 8

This guide describes a step-by-step tutorial on how to install LAMP stack on Rocky Linux 8, CentOS 8 and AlmaLinux 8.

Install 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 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;

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.

How To Install Wine 6 on Rocky Linux 8 Desktop

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

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

That concludes our guide on how to install LAMP Stack on Rocky Linux 8.

2 Trackbacks / Pingbacks

  1. Install PHP Composer on Rocky Linux 8 - LinuxStoney
  2. Install MariaDB 10.6 on Rocky Linux 8 - LinuxStoney

Leave a Reply

Your email address will not be published.


*