How to Install LAMP Stack on Rocky Linux 8

A LAMP stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL database, and dynamic content is processed by PHP.

Install Apache Web Server

First, we will start by installing the Apache web server. To complete the installation, use the following command.

yum install httpd httpd-tools


[root@server ~]# yum install httpd httpd-tools
Last metadata expiration check: 2:04:33 ago on Thu 06 May 2021 11:33:45 AM EDT.
Dependencies resolved.
 Package           Arch   Version                               Repo       Size
 httpd             x86_64 2.4.37-30.module+el8.3.0+124+cde66633 appstream 1.5 M
 httpd-tools       x86_64 2.4.37-30.module+el8.3.0+124+cde66633 appstream 103 k
Installing dependencies:
 apr               x86_64 1.6.3-11.el8                          appstream 124 k
 apr-util          x86_64 1.6.1-6.el8                           appstream 104 k
 httpd-filesystem  noarch 2.4.37-30.module+el8.3.0+124+cde66633 appstream  36 k

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

systemctl enable httpd

systemctl start httpd

systemctl status httpd


[root@server ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>
   Active: active (running) since Thu 2021-05-06 13:39:18 EDT; 6s ago
     Docs: man:httpd.service(8)
 Main PID: 9517 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 4956)
   Memory: 25.0M
   CGroup: /system.slice/httpd.service
           ├─9517 /usr/sbin/httpd -DFOREGROUND
           ├─9518 /usr/sbin/httpd -DFOREGROUND
           ├─9519 /usr/sbin/httpd -DFOREGROUND

To make your pages available to public, you will have to edit your firewall rules to allow HTTP and HTTPS requests on your web server by using the following commands.

firewall-cmd --permanent --zone=public --add-service=http 

firewall-cmd --permanent --zone=public --add-service=https 

firewall-cmd --reload


[root@server ~]# firewall-cmd --permanent --zone=public --add-service=http
[root@server ~]# firewall-cmd --permanent --zone=public --add-service=https
[root@server ~]# firewall-cmd --reload

Verify that the web server is running and accessible by accessing your server’s IP address.

echo "Hello there, Apache webserver is now running" > /var/www/html/index.html

And restart tht Web Server to reflect the changes made.

systemctl restart httpd

From your browser,



Install PHP

To get a list of all the PHP modules, run the command.

dnf module list php 


[root@vps ~]# dnf module list php
Last metadata expiration check: 0:36:51 ago on Monday 14 March 2022 05:07:41 PM 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 [e]    common [d], devel, minimal   PHP scripting language  

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

To install PHP 7.4, need to enable the module.

dnf module enable php:7.4

To install latest version of PHP on your RHEL 8 use the command below.

yum install -y php php-zip php-intl php-mysqlnd php-dom php-simplexml php-xml php-xmlreader php-curl php-exif php-ftp php-gd php-iconv  php-json php-mbstring php-posix php-sockets php-tokenizer

Verify the PHP Version,

php -v


[root@vps ~]# php -v
PHP 7.4.19 (cli) (built: May  4 2021 11:06:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.19, Copyright (c), by Zend Technologies

Now restart your web server so that Apache knows that it will be serving PHP requests as well.

systemctl restart httpd 

Test your PHP, by creating a simple info.php file with a phinfo() in it. The file should be placed in the directory root for your web server, which is /var/www/html.

To create the file use:

echo "<?php phpinfo() ?>" > /var/www/html/info.php

Now again, access http://localhost/info.php or http://yourserver-ip-address/info.php. You should see a page similar to below one.


Install MariaDB Server

MariaDB is a popular database server. The installation is simple and requires just a few steps as shown.

yum install mariadb-server mariadb


[root@server ~]# yum install mariadb-server mariadb
Last metadata expiration check: 2:23:42 ago on Thu 06 May 2021 11:33:45 AM EDT.
Dependencies resolved.
 Package                    Arch   Version                      Repo       Size
 mariadb                    x86_64 3:10.3.28-1.module+el8.3.0+126+a7f7b5c5
                                                                appstream 6.0 M
 mariadb-server             x86_64 3:10.3.28-1.module+el8.3.0+126+a7f7b5c5
                                                                appstream  16 M
Installing dependencies:
 libaio                     x86_64 0.3.112-1.el8                baseos     31 k

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

systemctl enable mariadb

systemctl start mariadb

systemctl status mariadb


[root@server ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pre>
   Active: active (running) since Thu 2021-05-06 13:59:14 EDT; 2s ago
     Docs: man:mysqld(8)
  Process: 13127 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, s>
  Process: 12990 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service>
  Process: 12966 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, sta>
 Main PID: 13095 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 4956)

Finally, you will want to secure your MariaDB installation by issuing the following command.



[root@server ~]# mysql_secure_installation


In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Once secured, you can connect to MySQL and review the existing databases on your database server by using the following command.

mysql -e "SHOW DATABASES;" -p


[root@server ~]# mysql -e "SHOW DATABASES;" -p
Enter password:
| Database           |
| information_schema |
| mysql              |
| performance_schema |