How to install LAMP on Linux 9

Share on Social Media

In this Linux tutorial, you will learn how to install LAMP on Linux 9 or other Red Hat based Linux distributions. #centlinux #linux #apache #mysql

What is LAMP Stack?:

LAMP (Linux, Apache, MySQL, PHP/Perl/Python) is an acronym denoting one of the most common software stacks for many of the web’s most popular applications. However, LAMP now refers to a generic software stack model and its components are largely interchangeable.

Each letter in the acronym stands for one of its four open-source building blocks:

  • Linux for the operating system
  • Apache HTTP Server
  • MySQL for the relational database management system
  • PHP, Perl, or Python programming language

The components of the LAMP stack are present in the software repositories of most Linux distributions. Now e-commerce, e-learning, SAAS, real estate, infotainment, and social media applications are developed using LAMP stack development processes.

To understand the nuts and bolts of the most popular web server, we highly recommend that you should attend online training: Apache Web Server

Video to install LAMP on Linux:

YouTube player

Environment Specification:

We are using a minimal Rocky Linux 9 server with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating SystemRocky Linux release 9.1 (Blue Onyx)
  • Hostname –
  • IP Address –

Prepare your Rocky Linux Server:

Use a ssh client and login to your Linux server as root user.

Set a hostname and configure Local DNS resolver for your Linux machine.

# hostnamectl set-hostname
# echo " lamp-01" >> /etc/hosts

Execute following command to update software packages in your Linux operating system.

# dnf update -y

Sometimes, Linux Kernel or relevant packages may be updated by the above command.

If this happens, then you should reboot your Linux operating system with newly installed Linux Kernel.

# reboot

Check your Linux operating system and Linux Kernel versions.

# cat /etc/rocky-release && uname -r
Rocky Linux release 9.1 (Blue Onyx)

Install LAMP on Linux:

Here, we are installing LAMP Stack components: Apache, MariaDB and PHP.

All three components are available in standard yum repositories of Rocky Linux 9.

Therefore, you can install all required components of LAMP stack on your Linux server by using a single dnf command.

# dnf install -y httpd httpd-tools mariadb-server mariadb php php-cli php-fpm php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd

Enable and start Apache, PHP and MariaDB services.

# systemctl enable --now httpd php-fpm mariadb
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/php-fpm.service.
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/mariadb.service.

Set a password for root (database user) and configure your MariaDB server instance as follows.

# mariadb-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
haven't set the root password yet, you should just press enter here.

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

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

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the 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!

To verify the installation of MariaDB server, you can login to mysql shell as root user.

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 11
Server version: 10.5.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> show databases;
| Database           |
| information_schema |
| mysql              |
| performance_schema |
3 rows in set (0.001 sec)

MariaDB [(none)]> exit

Verify PHP installation by checking the version of php command.

# php -v
PHP 8.0.27 (cli) (built: Jan  3 2023 16:17:26) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.27, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.27, Copyright (c), by Zend Technologies

Verify Apache installation by checking the version of httpd command.

# httpd -v
Server version: Apache/2.4.53 (Rocky Linux)
Server built:   Jan 31 2023 00:00:00

You need to create a PHP homepage for your LAMP server. We are using the phpinfo() function, because it generates a long webpage of useful information related to your Linux server and LAMP components.

# echo "<?php phpinfo ();?>" > /var/www/html/index.php

Configure Linux Firewall:

To make your LAMP server accessible from the network, you need to allow the http service in Linux firewall.

# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload

Access Your LAMP Server:

After successful configurations, you can access your LAMP server by opening URL in a web browser.

PHPinfo Page


In this Linux tutorial, you have learned how to install LAMP on Linux 9 or other Red Hat based Linux distributions. Apache 2 Pocket Reference (PAID LINK) by Andrew Ford is a quick reference book every Apache administrator should have, and we also advise you to keep the same.