How to Install LAMP Stack in AlmaLinux 8.4

LAMP is a popular hosting stack used for developing and testing web applications. It’s an acronym for Linux, Apache, MariaDB, & PHP.

Apache is an open-source and widely used web server. MariaDB is an open-source relational database server that stores data in tables inside databases, and PHP is a server-side scripting language used for developing dynamic web pages.

In this walkthrough, we will demonstrate the installation of the LAMP stack in AlmaLinux.

Step 1: Install Apache in AlmaLinux

We start off with the installation of the Apache webserver. The Apache httpd package is hosted on the AppStream repository. As such, you can install Apache using the DNF package manager as follows:

$ sudo dnf install -y @httpd
Install Apache in AlmaLinux
Install Apache in AlmaLinux

When the installation of Apache is done, proceed and start the Apache service as shown.

$ sudo systemctl start httpd

You would also want to enable the Apache webserver to start when the system is powered on or upon a reboot. Therefore, enable the Apache service.

$ sudo systemctl enable httpd

To be sure that Apache is running, run the command:

$ sudo systemctl status httpd
Check Apache in AlmaLinux
Check Apache in AlmaLinux

The output is a clear indication that Apache is running as expected.

We can also test that Apache is active by browsing the server’s IP or domain name. But first, if you have Firewalld enabled, you need to allow HTTP traffic across the firewall.

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

To apply the changes, reload the firewall.

$ sudo firewall-cmd --reload

You can now proceed to browse the server’s IP address as shown.

http://server-ip-address
OR
http://your-domain.com

The Apache welcome page will come to view, a confirmation that the webserver was successfully set up.

Verify Apache in AlmaLinux
Verify Apache in AlmaLinux

Step 2: Install MariaDB in AlmaLinux

Moving on, we are going to install MariaDB – is a relational database management system (RDBMS) which is a fork of MySQL. MariaDB is also available from the AppStream repository. You can list the available versions of MariaDB by running the following command

$ sudo dnf module list mariadb
List MariaDB in AlmaLinux
List MariaDB in AlmaLinux

From the output, the default version is MariaDB 10.3. However, we will install 10.5 which is the latest one in the repository.
For this to happen, reset the MariaDB module as follows.

$ sudo dnf module reset mariadb

Then install the latest MariaDB version using the command:

$ sudo dnf module install mariadb:10.5
Install MariaDB in AlmaLinux
Install MariaDB in AlmaLinux

Once complete, be sure to start the MariaDB service.

$ sudo systemctl start mariadb

Then enable MariaDB to start every time the system is booted or upon a reboot.

$ sudo systemctl enable mariadb

Just to confirm that the relational database server is up and running, execute:

$ sudo systemctl status mariadb
Check MariaDB in AlmaLinux
Check MariaDB in AlmaLinux

MariaDB’s default settings are weak and pose a potential security risk to the server. As such, we will go a step further and harden MariaDB. Run the script shown.

$ sudo mysql_secure_installation

You will be taken through a couple of prompts. Be sure to first set the root password.

Set MariaDB Root Password
Set MariaDB Root Password

For the remainder of the prompts, answer 'Y' to tweak it to the recommended settings. This involves removing anonymous users, blocking remote root login, and removing the test database.

Secure MariaDB in AlmaLinux
Secure MariaDB in AlmaLinux

To log in to your database server run the command.

$ sudo mysql -u root -p

Step 3: Install PHP 8 in AlmaLinux

The final component of the LAMP stack that we are going to install is PHP. This is a server-side scripting language for the development of dynamic web applications.

To check the PHP versions available in the AppStream repository, run:

$ sudo dnf module list php

The latest version offered by AppStream repo is PHP 7.4.

List PHP in AlmaLinux
List PHP in AlmaLinux

However, if you wish to install the very latest version of PHP, you need to install the Remi repository. This is a third-party repository that provides the latest PHP versions.

Install Remi repository on AlmaLinux as follows:

$ sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Install Remi in AlmaLinux
Install Remi in AlmaLinux

Once again, list the PHP modules offered and this time, you will get the Remi repository on the list with the PHP modules offered.

$ sudo dnf module list php

At the time of writing this guide, the latest PHP version is PHP 8.1 which is a Release Candidate. This is the equivalent of a Beta version and should only be used for testing purposes and not production.

List PHP Module in AlmaLinux
List PHP Module in AlmaLinux

To install the latest PHP module, reset the default PHP module and enable PHP 8.1 module as follows.

$ sudo dnf module reset php
$ sudo dnf module enable php:remi-8.1
Install PHP in AlmaLinux
Install PHP in AlmaLinux

Finally, install PHP and other PHP modules of your preference as shown.

$ sudo dnf install php php-common php-cli php-mbstring php-xml php-zip php-mysqlnd php-opcache php-curl php-intl php-gd
Install PHP Modules in AlmaLinux
Install PHP Modules in AlmaLinux

When the installation is complete, verify the version of PHP installed.

$ php -v
Check PHP in AlmaLinux
Check PHP in AlmaLinux

In addition to that, you can test PHP on the browser by first creating a test PHP file as shown.

$ sudo vim /var/www/html/info.php

Next, paste the following PHP files.

<?php
phpinfo();
?>

Save the changes and exit the file. Restart Apache webserver.

$ sudo systemctl restart httpd

Then browse the URL shown.

http://server-ip/info.php
OR
http://your-domain.com/info.php

This should direct you to the PHP info page indicating the version of PHP installed among other details.

Check PHP Info in AlmaLinux
Check PHP Info in AlmaLinux

And this concludes this tutorial on the installation of the LAMP stack on AlmaLinux. You can now start hosting Apache Virtual Hosts to run your web applications and secure your Apache with HTTPS.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.