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
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
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.
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
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
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
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.
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.
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.
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
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.
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
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
When the installation is complete, verify the version of PHP installed.
$ php -v
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.