LAMP is a stack of open-source software that provides a fully functional web server environment for various PHP and other web applications. LAMP stands for Linux, Apache, MySQL, PHP/Perl/Python, and here we learn how to install them on the CentOS alternative AmlaLinux 8.x server.
The primary function of a web server is to deliver HTML and image content via the HTTP or HTTPS protocol. Whenever we type some web address in our browser, it requests the webserver for the delivery of the called web page available on the Web server using either port 80 (“HTTP: //”) or port 443 (“HTTPS: //”).
The Apache HTTP server is one of the most widely used web servers. It has been around for 20 years and powers millions of web servers. However, there are a couple of good alternatives, such as the Nginx Web server, which uses PC resources more sparingly and is often better suited for less powerful hardware and servers with many accesses. Combining Apache with Nginx as a reverse proxy can be helpful in some cases.
Steps to Install LAMP Server on AlmaLinux 8
The steps are given here to install and set up a Lamp server on AlmaLinux 8. It can also be used for CentOS 8 Stream and RHEL 8 Linux servers or desktop systems.
1. Run system update
Most of the time, before starting any tutorial, I recommend readers run a system update command. This will not only make sure all the installed packages are in their latest state but also rebuild the system repository cache. This helps make any software or service installation run smoothly.
sudo dnf update
2. Install Apache web server on AlmaLinux 8
The next step is to install the Apache webserver on AlmaLinux along with some other tools to run httpd on this free RHEL is based on the Linux operating system. Run the below command:
sudo dnf install httpd httpd-tools

3. Enable and start Apache
Once the webserver is installed, let’s start its service and make it automatically fire up with the system boot. This will ensure that whenever you boot AlmaLinux, you won’t need to start Apache manually.
Start it:
sudo systemctl start httpd
Enable it:
sudo systemctl enable httpd
Check the status of the web Server service to ensure everything is running without any error.
sudo systemctl status httpd

4. Update FireWall rules
If you want to access the Apache webserver outside your local machine using some browser, then first, we have to open ports 80 and 443 on our AlmaLinux server.
To open port 80 or HTTP:
sudo firewall-cmd --permanent --zone=public --add-service=http
For allowing port 443 or HTTPS:
sudo firewall-cmd --permanent --zone=public --add-service=https
Reload firewall to make changes into effect
sudo firewall-cmd --reload
Now, we can connect to our AlmaLinux Apache web server by calling it in the browser. To do so, open your browser and type the IP address of the server where you have installed the Apache.
http://your-server-ipadress

5. Install MySQL or MariaDB on AlmaLinux8
MySQL is an open-source database developed by Oracle, whereas MariaDB is a fork that works similarly and uses the same command line as MySQL. You can install either of them, but don’t install both.
Command for MySQL
sudo dnf install mysql-server mysql
or
For MariaDB
sudo dnf install mariadb-server mariadb -y


Command to Start & Enable MySQL and MariaDB services
For MySQL:
sudo systemctl start mysqld
sudo systemctl enable mysqld
To check status:
sudo systemctl status mysqld
For MariaDB
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl status mariadb

6. Secure MySQL installation
This step will be the same whether you are using MySQL or MariaDB. It will give you some options to follow and set some settings so that you can secure your Database from any common future threats.
mysql_secure_installation
You can set a root password for MySQL or MariaDB, remove empty databases, restrict remote access except for localhost, remove anonymous users, and more.

7. Install PHP 7.2/7.3/7.4 or 8.0 on AlmaLinux 8
PHP is a popular scripting language that powers the dynamic content of millions of websites and apps. Therefore, if you are planning to install a web CMS like WordPress, you have to set up PHP on your AlmaLinux server.
First, check what PHP versions are available to install:
sudo dnf module list php

As you can see while writing the article, the latest version of PHP in the default system’s AppStream repo was 7.4, although PHP 8 is already there. However, lots of web applications still support PHP 7. Thus, to provide wide compatibility and stability, one can go for PHP 7.4.
Also by default, it will install PHP 7.2, to change that we need to configure and set 7.4 as the default/enable in the repo. For that run:
sudo dnf module reset php
sudo dnf module enable php:7.4
The above command changes the default version on the system repo for installation.

—————————————————————————————————————
(Optional Step): Those who want the latest PHP 8.0 or any other version on their AlamLinux 8, can follow these steps:
1. Add Remi Repository
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
2. Run system update
sudo dnf update
3. Check available Latest PHP versions
sudo dnf module list php

To install it, first you have to set Remi’s PHP 8.0 as the default version to install on AlmaLinux 8, for that run:
sudo dnf module reset php
sudo dnf module enable php:remi-8.0
—————————————————————————–
Finally, run the command to install PHP and common extensions we require to use it with Apache and Mysql on our system:
sudo dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd

To get better performance for various applications using PHP, we can start (if not already) and enable PHP-FPM (FastCGI Process Manager) using the below commands:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
8. Test PHP
We have already installed Apache, MySQL, and PHP on our system. Let’s check whether PHP is working absolutely fine by calling its configuration detail in the browser.
sudo nano /var/www/html/info.php
If you don’t have a nano text editor, then use vi, and the above command will be: sudo vi /var/www/html/info.php
Add the following line in the info.php file we have created using the above command:
<?php
phpinfo ();
?>
To save the file, type Ctrl+X, press the Y key, and then Enter.
Whereas, the users using VI editor- first to copy-past the above line they have to press Insert button and then Esc once editing is done followed by :qw to save and exit it.
Now, open your browser and type your server IP address along with file name info.php, we have created above:
http://your-server-ipaddress/info.php

To remove this file type:
sudo rm /var/www/html/info.php
9. Install phpMyAdmin
If you also want to manage your MySQL or MariaDB database using web graphical user interface, then see our article: Install phpMyAdmin on AlmaLinux 8 with Apache
Conclusion:
These were some simple but detailed steps for installing and configuring Apache, MySQL, and PHP on AlamLinux 8 Server. In case you want to know something else related to this Linux or topic, the comment section is all yours.
I needed to restart apache after installing php for my phpinfo() script to show correctly in a browser, using: sudo service restart httpd