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
|Category||Requirements, Conventions or Software Version Used|
|Software||LAMP (Apache, MySQL/MariaDB, PHP)|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
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.
- 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
- 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
- Start both Apache webserver and MariaDB services:
# systemctl start mariadb # systemctl start httpdEnable MariaDB and httpd to start after system reboot:
# systemctl enable mariadb # systemctl enable httpd
- 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.
- To confirm that our web server is accessible and that PHP is working as expected, we can create a file called
/var/www/htmldirectory. The file should contain the following line, which verifies whether PHP is working or not.
<?php phpinfo(); ?>
- 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
- 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.
- 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 PACKAGENAMEOnce the package is installed, reload the httpd service for the changes to take effect:
# systemctl reload httpd
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.