How to install LAMP on AlmaLinux 8 (Apache, MySQL and PHP)

install lamp on almalinux

LAMP stands for Linux, Apache, MySQL, PHP/Perl/Python and here we learn how to install LAMP on AlmaLinux 8. We recommend AlmaLinux 8 because it is a very popular free enterprise Linux distribution, a CentOS Linux alternative.


  • Create a Scalable VPS with AlmaLinux 8 
  • Connect to your VPS Cloud Server via SSH
  • Install Apache HTTP Server
  • Then Install MySQL or MariaDB Server
  • Finally Install PHP
  • Test the LAMP stack
  • Transfer files and start using your LAMP stack

Installing Apache HTTP Server

  1. Perform a system update first by using the following command. This ensures the system installed packages are in their latest state as well as rebuild the system repository cache:
    dnf update
  2. To install Apache webserver in AlmaLinux 8, simply execute the following command:
    dnf install httpd httpd-tools
  3. Once Apache webserver is installed, run the following command to start the Apache HTTP server
    systemctl start httpd
  4. To ensure that Apache webserver will be started each time you restart your server, run this command:
    systemctl enable httpd
  5. Finally, check the status of Apache webserver to ensure everything runs smoothly:
    systemctl status httpd
  6. Now, you will need to make sure Apache webserver is accessible externally from the internet. Run this command to enable Port 80 (for http) on your firewall:
    firewall-cmd --permanent --zone=public --add-service=http
  7. You will also need to enable Port 443 (for https) on your firewall:
    firewall-cmd --permanent --zone=public --add-service=https
  8. Reload firewall for these changes to take effect:
    firewall-cmd --reload
  9. Test Apache webserver by loading your website (http://expertvm-server-ip-address) to confirm that the following page can be seen:
Apache test page on AlmaLinux
Apache HTTP server test page on AlmaLinux

Installing MySQL or MariaDB Server

  1. Depending on your preference, use either one of the following command lines:To install MySQL
    dnf install mysql-server mysql

    To install MariaDB

    dnf install mariadb-server mariadb
  2. Use these commands to start the database servers and to ensure the service will be started automatically after a server reboot:For MySQL
    systemctl start mysql
    systemctl enable mysql

    For MariaDB

    systemctl start mariadb
    systemctl enable mariadb
  3. Check the status of the database servers:For MySQL
    systemctl status mysql

    For MariaDB

    systemctl status mariadb
  4. Secure MySQL or MariaDB database installation using the following command (it is the same regardless of your choice of database server):
  5. Follow through the on-screen instructions to complete the secure installation process.

Installing PHP on AlmaLinux 8

  1. Run the following command to check the PHP versions that are available
    dnf module list php
  2. At the time of writing this blog, you may only be able to see PHP 7.x. If you wish to install PHP 8, run the following commands to include the Remi Repository, perform system update and then you will be able to see PHP 8 available this time:
    dnf install
    dnf update
    dnf module list php
  3. Run the following commands to set your preferred PHP version as the default one:

    For PHP 7.4

    dnf module reset php
    dnf module enable php:7.4

    For PHP 8.0

    dnf module reset php
    dnf module enable php:remi-8.0
  4. Run the following command to enable the common PHP extensions
    dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd
  5. For better performance, enable PHP-FPM (FastCGI Process Manager) using the below command:
    systemctl start php-fpm
    systemctl enable php-fpm
  6. Restart Apache HTTP server:
    systemctl restart httpd


This tutorial shows you how to install LAMP on AlmaLinux 8. Enjoy hosting your own website within your own server environment!

Related Post