The LAMP stack (Linux, Apache, MySQL, PHP) provides a complete foundation for hosting websites and web applications. Installing it on AlmaLinux gives you a stable, enterprise-grade platform that powers everything from personal blogs to high-traffic business sites.
You will install and configure each component of the LAMP stack, open the necessary firewall ports and verify that all services work together correctly. Once complete, your server will be ready to host websites and run PHP applications with MySQL database support.
Before installing the LAMP stack components, you need to update existing packages and configure firewall rules. This ensures your server has the latest security patches and allows web traffic to reach Apache.
dnf update
Type y and press Enter when prompted to confirm the updates.
firewall-cmd --zone=public --list-services

--permanent flag ensures these rules persist after server restarts.firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
firewall-cmd --zone=public --list-services

Your server now accepts incoming web traffic. You can proceed with installing Apache.
Apache handles incoming HTTP requests and serves web pages to visitors. You will install the httpd package (Apache’s name on Red Hat-based systems) and configure it to start automatically when your server boots.
y when prompted to confirm the installation.dnf install httpd

systemctl start httpd
systemctl enable httpd
Apache is now serving web pages. Next you will install MySQL to provide database functionality.
MySQL stores and manages data for your web applications. You will install the MySQL server, secure the installation by setting a root password and test the database connection.
dnf install mysql mysql-server
Type y when prompted to proceed with the installation.
systemctl start mysqld
systemctl enable mysqld
mysql_secure_installation
Follow the prompts to configure your security preferences. We recommend answering yes to all questions for maximum security.
mysql -u root -p
Enter your password when prompted. You will see the MySQL command prompt if the connection succeeds. Press Ctrl+D to exit.
Your database server is now secured and ready to store application data. The final component is PHP.
PHP processes dynamic content and connects your web applications to MySQL. You will enable a specific PHP version, install essential extensions and verify PHP works with Apache.
dnf module list php

8.2 with your preferred version if different. Enabling a module makes that version available for installation.dnf module enable php:8.2
dnf install php php-fpm php-zip php-intl php-opcache php-gd php-mbstring php-xml php-mysqlnd
nano /var/www/html/index.php
Add the following content to the file:
<?php phpinfo();?>
Press Ctrl+X, then Y, then Enter to save and exit.
systemctl restart httpd
http://your-server-ip/index.php replacing your-server-ip with your actual server address. You should see a detailed PHP information page listing all installed modules and configuration settings.Your LAMP stack is now fully installed and operational. All components work together to serve dynamic web content.
The LAMP stack remains one of the most widely deployed web hosting environments due to its maturity, extensive documentation and broad software compatibility. Each component has evolved significantly over the years while maintaining backwards compatibility with existing applications.
Apache’s modular architecture allows you to extend functionality through hundreds of available modules. Common additions include mod_rewrite for URL manipulation, mod_security for web application firewall capabilities and mod_ssl for HTTPS support. The Apache HTTP Server documentation provides comprehensive guides for configuring these modules and optimising server performance.
MySQL and its community fork MariaDB offer robust database management with support for complex queries, transactions and replication. Understanding database optimisation becomes important as your applications grow. The MySQL documentation covers indexing strategies, query optimisation and backup procedures that help maintain database performance under load.
PHP continues to evolve with regular releases that improve performance and add new features. Each major version introduces changes that may affect existing code, so testing applications before upgrading PHP versions prevents compatibility issues.
You have installed and configured a complete LAMP stack on AlmaLinux. Your server now runs Apache to handle web requests, MySQL to manage databases and PHP to process dynamic content. The firewall allows web traffic while maintaining security.
Test your setup by creating a simple PHP application that connects to MySQL. Monitor server logs in /var/log/httpd/ to identify any issues. Our VPS hosting provides the foundation for running custom LAMP configurations with full root access.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting