LAMP (Linux, Apache, MySQL/MariaDB, PHP) remains a common, well-understood stack for traditional web applications — this guide covers the complete setup specifically on AlmaLinux/Rocky Linux.
Step 1 — Install Apache (httpd)
sudo dnf install httpd -y
sudo systemctl enable --now httpd
See How to Install Apache (httpd) on AlmaLinux/Rocky Linux for more detail on this specific step.
Step 2 — Install MariaDB
sudo dnf install mariadb-server -y
sudo systemctl enable --now mariadb
sudo mysql_secure_installation
See How to Install MySQL/MariaDB on AlmaLinux/Rocky Linux for the complete database setup process.
Step 3 — Install PHP
sudo dnf install php php-mysqlnd php-fpm -y
See How to Install PHP on AlmaLinux/Rocky Linux for version-specific installation options via Remi's repository.
Step 4 — Configure Apache to Use PHP-FPM
sudo nano /etc/httpd/conf.d/php.conf
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
Step 5 — Start PHP-FPM
sudo systemctl enable --now php-fpm
Step 6 — Configure firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Step 7 — Test PHP Processing
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
http://YOUR_SERVER_IP/info.php
Remove this test file after confirming it works — leaving phpinfo() accessible publicly exposes server configuration details unnecessarily.
Step 8 — Create a Database and User for Your Application
sudo mysql -u root -p
CREATE DATABASE myapp;
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'CHANGE_ME';
GRANT ALL PRIVILEGES ON myapp.* TO 'myapp_user'@'localhost';
FLUSH PRIVILEGES;
SELinux Considerations for LAMP
See Understanding SELinux Basics on AlmaLinux/Rocky Linux — SELinux by default may restrict Apache/PHP from writing to certain directories or making outbound network connections (needed for some applications to reach external APIs); use setsebool for common web-server-related booleans rather than disabling SELinux outright.
Common SELinux Boolean for Web Applications
sudo setsebool -P httpd_can_network_connect on
Needed if your PHP application makes outbound HTTP requests (calling external APIs, for example) — without this, SELinux blocks such connections by default.
Adding HTTPS with Let's Encrypt
See How to Set Up Let's Encrypt SSL on AlmaLinux/Rocky Linux for completing the setup with proper TLS.
Common Errors
"403 Forbidden" despite correct file permissions — check SELinux context on your web files (ls -Z /var/www/html); files need the correct httpd_sys_content_t context, distinct from standard Unix file permissions alone.
Continue Reading
- How to Install Apache (httpd) on AlmaLinux/Rocky Linux
- How to Install PHP on AlmaLinux/Rocky Linux
- Understanding SELinux Basics on AlmaLinux/Rocky Linux
Browse more articles in AlmaLinux & Rocky Linux.