LAMP stack (Linux, Apache, MariaDB, or MySQL, and PHP) is a popular open-source web hosting stack used to support static and dynamic websites. It comprises the Apache web server, MariaDB database server, and PHP which is a backend scripting language used for developing dynamic web pages. In this guide, we’ll walk you through the steps required to install the LAMP stack on AlmaLinux 8.4.
As you know by now, AlmaLinux is one of the operating systems that is considered a perfect alternative to CentOS 8 after RedHat decided to prematurely discontinue CentOS 8 in favor of CentOS Stream. The other robust, stable, and enterprise-grade alternative is Rocky Linux 8.
Without much further ado, let’s install LAMP on AlmaLinux 8.4
Step 1: Install Apache httpd Webserver
The Apache httpd web server is available in the AlmaLinux AppStream repository. Therefore, to install the webserver, run the command:
$ sudo dnf install -y @httpd
Once the webserver is installed, start and enable the service:
$ sudo systemctl start httpd $ sudo systemctl enable httpd
Just to confirm that Apache is running, execute the command
$ sudo systemctl status httpd
Additionally, you can use the netstat command as follows:
$ sudo netstat -pnltu | grep 80
Now that Apache is running, update the firewall rules to allow incoming HTTP and HTTPS requests to the webserver
$ sudo firewall-cmd --permanent --zone=public --add-service=http $ sudo firewall-cmd --permanent --zone=public --add-service=https $ sudo firewall-cmd --reload
With HTTP & HTTPS protocols allowed across the firewall, open your browser and navigate to the following URL.
This should display the Apache Welcome page – yet another confirmation that the webserver is running as expected,
Step 2: Install PHP 8.0 on AlmaLinux 8
In this guide, we will install PHP 8.0 which is the latest version of PHP at the time of penning down this guide. To install PHP 8.0 on AlmaLinux, run the steps given below:
First, add the Remi repository to AlmaLinux 8.
$ sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Next, update your system packages:
$ sudo dnf update
Thereafter, proceed and check the versions of PHP provided or offered by Remi repository.
$ sudo dnf module list php
From the output, we can see that PHP 8.0 is the latest PHP module available in the Remi repository. Before installing it, first reset the default modules on your local system.
$ sudo dnf module reset php
The enable the latest module:
$ sudo dnf module enable php:remi-8.0
Finally, install PHP 8.0 and your preferred PHP extensions as follows. Here, the extensions take the form php-extension.
$ sudo dnf install php php-fpm php-mysqlnd php-opcache php-gd php-xml php-mbstring php-zip
Step 3: Test PHP installation
To verify the version of PHP installed, run the command:
$ php --version
Additionally, you can verify the installation from a webserver. To do that, first, create an info.php file in the document root directory.
$ sudo vim /var/www/html/info.php
Next, paste the below contents into the file:
<?php phpinfo(); ?>
Save the file and exit.
Open your browser and browse the URL shown.
You should get the PHP page shown below indicating the version of PHP installed and other detailed information regarding the PHP extensions.
Step 4: Install MariaDB server and client
MariaDB is a popular Relational database server that is a fork of MySQL. It’s robust, fast, scalable, and provides enhanced features such as better security, faster replication, and additional storage engines which improve overall performance.
To install MariaDB on AlmaLinux run:
$ sudo dnf -y install mariadb-server mariadb
Once the installation is done, start the service and enable it to run automatically on system boot.
$ sudo systemctl start mariadb $ sudo systemctl enable mariadb
The default settings are not strong enough and attackers can leverage on that breach the database server. Some extra steps are needed to harden the server.
To secure your database server from common threats by run the following script:
$ sudo mysql_secure_installation
Follow the remaining steps and type ‘Y’ to apply the recommended settings to secure your database server.
You have successfully installed and secured the MariaDB server.
To log in run
$ sudo mysql -u root -p
That’s it! We have successfully walked you through how to install LAMP on AlmaLinux 8.4 server. You can now start testing and hosting your web applications. Any queries or feedback regarding this guide? Feel free to reach out.