Share your love
Install LAMP Stack on AlmaLinux 9

This guide intends to teach you How To Install LAMP Stack on AlmaLinux 9.
The LAMP stack is a popular open-source solution stack used primarily in web development.
LAMP consists of four components necessary to establish a fully functional web development environment. The first letters of the components’ names make up the LAMP acronym:
- Linux is an operating system used to run the rest of the components.
- Apache HTTP Server is a web server software used to serve static web pages.
- MySQL is a relational database management system used for creating and managing web databases, but also for data warehousing, application logging, e-commerce, etc.
- PHP is a programming language used to create web applications.
Each component represents an essential layer of the stack. Together, the components are used to create database-driven, dynamic websites.
Steps To Install LAMP Stack on AlmaLinux 9
To complete this guide, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide the Initial Server Setup with AlmaLinux 9.
Install Apache on AlmaLinux 9
You need to install Apache as a web server on AlmaLinux 9. First, update your local package index with the following command:
sudo dnf update
Then, install Apache with the command below:
sudo dnf install httpd
When your installation is completed, start and enable your Apache service on AlmaLinux 9 with the commands below:
sudo systemctl enable httpd
sudo systemctl start httpd
Verify that your service is active and running on your server with the following command:
sudo systemctl status httpd
In your output you will see:
Output ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor pre> Active: active (running) since Tue 2022-09-20 03:48:24 EDT; 6s ago Docs: man:httpd.service(8) Main PID: 4651 (httpd) Status: "Started, listening on: port 80" Tasks: 213 (limit: 23609) Memory: 27.0M CPU: 123ms CGroup: /system.slice/httpd.service ...
Here we assumed that you have enabled firewalld from the requirements, now you need to allow traffic for Apache through the AlmaLinux firewall with the following command:
sudo firewall-cmd --add-service=http --permanent
Reload the firewall to apply the new rules:
sudo firewall-cmd --reload
Now you can access the Apache default page by typing your server’s IP address in your web browser:
http://server-IP-address
you will see:

Install MariaDB on AlmaLinux 9
At this point, we use MariaDB as our database server.
By default, MariaDB is available on the AlmaLinux 9 base repository. Simply install the MariaDB package by using the dnf
command:
sudo dnf install mariadb-server mariadb
When your installation is completed, start and enable your service with the following command:
sudo systemctl enable mariadb
sudo systemctl start mariadb
Verify that your service is active and running on your server with the following command:
sudo systemctl status mariadb
Output
● mariadb.service - MariaDB 10.5 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor p>
Active: active (running) since Tue 2022-09-20 03:53:05 EDT; 6s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 7431 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, >
Process: 7453 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.serv>
Process: 7550 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited>
Main PID: 7535 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 14 (limit: 23609)
Memory: 73.3M
...
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation
script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
sudo mysql_secure_installation
Enter current password for root (enter for none): Set root password? [Y/n] Y New password: Re-enter new password: Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Reload privilege tables now? [Y/n] Y
To log in to your MariaDB console you can use the following command:
sudo mysql -u root -p
Outtput
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
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)]>
Set up PHP on AlmaLinux 9
By default, PHP 8.0 is available in the default AlmaLinux 9 repository.
To install PHP part from the LAMP stack and the most common PHP extensions on your server, run the command below:
sudo dnf install php php-curl php-bcmath php-gd php-soap php-zip php-curl php-mbstring php-mysqlnd php-gd php-xml php-intl php-zip
Verify your PHP installation by checking its version:
php -v
Output
PHP 8.0.13 (cli) (built: Nov 16 2021 18:07:21) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies
Also, you can test your PHP from your web server.
To confirm that our web server is accessible and that PHP is working as expected, create and open a smile PHP file with your favorite text editor, here we use vi:
sudo vi /var/www/html/info.php
Add the following content to the file:
<?php phpinfo(); ?>
When you are done, save and close the file.
Restart Apache to apply the changes:
sudo systemctl restart httpd
Now in your web browser type your server’s IP address followed by /info.php:
http://server-IP/info.php
You will see your PHP information in detail:

After you have read your PHP info, for more security it’s better to remove it with the command below:
sudo rm /var/www/html/info.php
Conclusion
At this point, you have learned to Install LAMP Stack on AlmaLinux 9.
Hope you enjoy it.