A LAMP stack is an assortment of software that contains everything you need in order to serve a website, show dynamic content, and store or retrieve data from a database. The software is all within the LAMP acronym, namely the Linux operating system, Apache web server, MySQL database (or MariaDB alternatively), and PHP programming language.

If you've installed AlmaLinux or migrated from CentOS to AlmaLinux, then you already have the first requirement done. Next, you just need to get your LAMP stack up and running. In this guide, we'll show the step by step instructions to install a LAMP stack on AlmaLinux.

In this tutorial you will learn:
  • How to install all LAMP prerequisite packages on AlmaLinux
  • How to secure MariaDB database
  • How to start httpd and MariaDB services
  • How to open HTTP and HTTPS firewall ports
LAMP stack running successfully on AlmaLinux
LAMP stack running successfully on AlmaLinux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System AlmaLinux
Software LAMP (Apache, MySQL/MariaDB, PHP)
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Install and configure LAMP packages on AlmaLinux

Follow along with the steps below to get Apache, MariaDB, and PHP setup and configured on AlmaLinux.

For this guide, we'll be installing MariaDB instead of the official MySQL server package. MariaDB is an open source implementation of MySQL and works exactly the same, but it has a few more features. If you don't want to install MariaDB, feel free to install MySQL instead.
  1. Execute the following command to install Apache, MariaDB, PHP, and some additional PHP modules with the dnf package manager.
    # dnf install httpd mariadb-server php-mysqlnd php-fpm

    Subscribe to RSS and NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.

  3. If you have the default firewalld enabled on AlmaLinux, you'll have to open up ports 80 and 443 for incoming HTTP and HTTPS connections to your web server.
    # firewall-cmd --permanent --zone=public --add-service=http 
    # firewall-cmd --permanent --zone=public --add-service=https
    # firewall-cmd --reload
  4. Start both Apache webserver and MariaDB services:
    # systemctl start mariadb
    # systemctl start httpd
    Enable MariaDB and httpd to start after system reboot:
    # systemctl enable mariadb
    # systemctl enable httpd

  5. Execute the following command to secure your MariaDB installation and set the root password. There will be a few prompts to go through. It's recommended that you disable remote root login when the question shows up, unless you have some circumstance that requires it.
    # mysql_secure_installation
  6. To confirm that our web server is accessible and that PHP is working as expected, we can create a file called info.php inside the /var/www/html directory. The file should contain the following line, which verifies whether PHP is working or not.
    <?php phpinfo(); ?>
  7. Change permissions of the web server directory, and change the SELinux security context.
    # chown -R apache:apache /var/www/html/*
    # chcon -t httpd_sys_rw_content_t /var/www/html/ -R
  8. In your browser, navigate to the test page we've created by opening the URL at http://localhost/info.php. You should see a result like the one in the screenshot below.
  9. LAMP stack running successfully on AlmaLinux
    LAMP stack running successfully on AlmaLinux
  10. So far, we have just installed a bare bones LAMP stack. Depending on the application you are going to use, you might also need to install additional PHP modules. To see a list of modules that are available for installation from the system's package manager, execute the following command in terminal.
    # dnf search php-
    Then, to install an additional package, execute:
    # dnf install PACKAGENAME
    Once the package is installed, reload the httpd service for the changes to take effect:
    # systemctl reload httpd

Closing Thoughts

In this guide, we saw how to install and configure a LAMP stack on AlmaLinux. This involved installing the individual software packages, namely Apache, MariaDB, and PHP. Your system is now ready to serve and store dynamic web content.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
Get extra help by visiting our LINUX FORUM or simply use comments below.