How To Install LAMP STACK ON Rocky Linux 8.6

To Install LAMP STACK on Rocky Linux 8.6

Introduction

LAMP is an abbreviation for Linux Apache MySQL PHP. It is an open-source Web development platform that uses Linux as the server operating system, Apache as the Web server, MySQL as the relational database management system, and PHP as the object-oriented scripting language.

Installation Procedure:

STEP 1: Check the OS version by using the below command

[root@linuxhelp ~]# cat /etc/os-release 
NAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL=https://rockylinux.org/

STEP 2: Now Install Apache Server by using the below command

[root@linuxhelp ~]# yum install httpd* 
Last metadata expiration check: 0:12:50 ago on Thu 23 Jun 2022 05:35:30 AM IST.
Package httpd-2.4.37-47.module+el8.6.0+985+b8ff6398.2.x86_64 is already installed.
Package httpd-filesystem-2.4.37-47.module+el8.6.0+985+b8ff6398.2.noarch is already installed.
Package httpd-tools-2.4.37-47.module+el8.6.0+985+b8ff6398.2.x86_64 is already installed.
Dependencies resolved.
======================================================================================================
 Package               Arch        Version                                       Repository      Size
======================================================================================================
Installing:
 httpd-devel           x86_64      2.4.37-47.module+el8.6.0+985+b8ff6398.2       appstream      223 k
 httpd-manual          noarch      2.4.37-47.module+el8.6.0+985+b8ff6398.2       appstream      2.4 M
Installing dependencies:
 apr-devel             x86_64      1.6.3-12.el8                                  appstream      245 k
 apr-util-devel        x86_64      1.6.1-6.el8.1                                 appstream       85 k
 cyrus-sasl-devel      x86_64      2.1.27-6.el8_5                                baseos         127 k
 expat-devel           x86_64      2.2.5-8.el8                                   baseos          56 k
 libdb-devel           x86_64      5.3.28-42.el8_4                               appstream       46 k
 openldap-devel        x86_64      2.4.46-18.el8                                 baseos         810 k

Transaction Summary
======================================================================================================
Install  8 Packages

Total download size: 3.9 M
Complete!

STEP 3: Now Enable the Service by using the below command

[root@linuxhelp ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

STEP 4: Now Start the service by using the below command

[root@linuxhelp ~]# systemctl start httpd

STEP 5: Now Install MariaDB Server by using the below command

[root@linuxhelp ~]# yum install mariadb mariadb-server
Last metadata expiration check: 0:14:04 ago on Thu 23 Jun 2022 05:35:30 AM IST.
Dependencies resolved.
======================================================================================================
 Package                      Arch     Version                                      Repository   Size
======================================================================================================
Installing:
 mariadb                      x86_64   3:10.3.32-2.module+el8.5.0+777+18007c86      appstream   6.0 M
 mariadb-server               x86_64   3:10.3.32-2.module+el8.5.0+777+18007c86      appstream    16 M
Installing dependencies:
 mariadb-common               x86_64   3:10.3.32-2.module+el8.5.0+777+18007c86      appstream    63 k
 mariadb-connector-c          x86_64   3.1.11-2.el8_3                               appstream   199 k
 mariadb-connector-c-config   noarch   3.1.11-2.el8_3                               appstream    14 k
 mariadb-errmsg               x86_64   3:10.3.32-2.module+el8.5.0+777+18007c86      appstream   233 k
 perl-DBD-MySQL               x86_64   4.046-3.module+el8.6.0+904+ef468285          appstream   155 k
Installing weak dependencies:
 mariadb-backup               x86_64   3:10.3.32-2.module+el8.5.0+777+18007c86      appstream   6.1 M
 mariadb-gssapi-server        x86_64   3:10.3.32-2.module+el8.5.0+777+18007c86      appstream    50 k
 mariadb-server-utils         x86_64   3:10.3.32-2.module+el8.5.0+777+18007c86      appstream   1.1 M
Enabling module streams:
 mariadb                               10.3                                                          
 perl-DBD-MySQL                        4.046            

STEP 6: Now Enable the service by using the below command

[root@linuxhelp ~]# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.

STEP 7: Now Start the services by using the below command

[root@linuxhelp ~]# systemctl start mariadb.service

STEP 8: Make the MariaDB server secure by using the below command

[root@linuxhelp ~]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

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):


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!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

STEP 9: Install PHP Modules by using the below command

[root@linuxhelp ~]# yum install php php-mbstring  php-gd php-mysqlnd
Last metadata expiration check: 0:16:46 ago on Thu 23 Jun 2022 05:35:30 AM IST.
Package php-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 is already installed.
Dependencies resolved.
======================================================================================================
 Package             Architecture  Version                                     Repository        Size
======================================================================================================
Installing:
 php-gd              x86_64        7.2.24-1.module+el8.4.0+413+c9202dda        appstream         83 k
 php-mbstring        x86_64        7.2.24-1.module+el8.4.0+413+c9202dda        appstream        579 k
 php-mysqlnd         x86_64        7.2.24-1.module+el8.4.0+413+c9202dda        appstream        189 k
Installing dependencies:
 php-pdo             x86_64        7.2.24-1.module+el8.4.0+413+c9202dda        appstream        121 k

Transaction Summary
======================================================================================================
Install  4 Packages

STEP 10: Make .PHP extension file by using the below command

[root@linuxhelp ~]# vim /var/www/html/info.php

<?php
phpinfo();
?>

STEP 11: Restart The Apache Server by using the below command

[root@linuxhelp ~]# systemctl restart httpd.service

STEP 12: Go to the Browser and search http://192.168.6.121/info.php as shown in the below image

By this the installation process of Lamp Stack on Rocky Linux 8.6 has come to an end.

FAQ
Q
Which modules are used to connect MySQL with PHP?
A
The modules that are used to connect MySQL with PHP is php-mysqlnd
Q
What language should you use to write a query for a database?
A
The language used to write a query for a database is MySQL.
Q
What is the location to create a PHP extension?
A
The location to create a PHP extension is /var/www/html/
Q
How to stop/start Apache Web Server?
A
To stop/start Apache Web Server by using the following command
systemctl start httpd
systemctl stop httpd
Q
What is Lamp Stack?
A
LAMP stands for Linux, Apache, MySQL, PHP