Migrating Apache & PHP App (RHEL7 → Rocky 8)

🚀 Migrating Apache + PHP App from RHEL 7 to Redhat/Alma/Rocky Linux 8 (No Code Changes)

Published on August 2, 2025

A step-by-step technical guide for updating your legacy Apache + PHP setup to Redhat/Alma/Rocky Linux 8 using PHP-FPM, while keeping all your application code intact.

🧩 Objectives

📦 Install Required Packages

        
sudo dnf module reset php -y
sudo dnf module enable php:7.4 -y
sudo dnf install httpd mod_fcgid php php-fpm php-cli php-common php-mysqlnd php-gd php-mbstring php-xml php-ldap -y

sudo mkdir -p /var/lib/php/session
sudo chown -R apache:apache /var/lib/php
        
    

🔧 Main Apache Configuration (httpd.conf)


ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache

DocumentRoot "/var/www/html"
<Directory "/var/www/html">
    AllowOverride None
    Require all granted
</Directory>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"
CustomLog "logs/access_log" combined

IncludeOptional conf.d/*.conf
    

🌐 Virtual Host Example (conf.d/site1.conf)


<VirtualHost *:80>
ServerName site1.example.com
DocumentRoot /srv/site1

<Directory "/srv/site1">
    Options Indexes MultiViews FollowSymLinks ExecCGI
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>
    

📄 Alias Setup (conf.d/aliases.conf)


Alias /scripts "/srv/legacy/scripts"
<Directory "/srv/legacy/scripts">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Require all granted
</Directory>
    

⚙️ PHP with FPM (conf.d/php.conf)


AddType application/x-httpd-php .php .html .htm

<FilesMatch \.(php|phar|html|htm)$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
    

🔧 PHP-FPM Settings (/etc/php-fpm.d/www.conf)


user = apache
group = apache
listen.owner = apache
listen.group = apache
listen.mode = 0660
    

setfacl -m u:apache:rwx /run/php-fpm/www.sock
systemctl enable --now php-fpm
systemctl enable --now httpd
    

🔍 Troubleshooting Cheatsheet

📦 Best Practices

✅ Summary

This guide allows safe migration from RHEL 7 + mod_php to Rocky Linux 8 + php-fpm with zero code changes, modern security, and strong upgrade paths.

📌 Next Steps

Last updated: August 2025