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.
httpd.conf and conf.d/.php and .html files
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
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
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>
conf.d/aliases.conf)
Alias /scripts "/srv/legacy/scripts"
<Directory "/srv/legacy/scripts">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Require all granted
</Directory>
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>
/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
FilesMatch block for handlerphp-ldap is installedconf.d/*.conf for flexibilityThis 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.
/etc/httpd, /etc/php-fpm.d, and /etc/php.iniLast updated: August 2025