Key Architecture Takeaways
- ›Point 1: Production blueprint for Install and Configure Multiple PHP Version with Apache on Ubuntu 20.04 on Linux infrastructure.
- ›Point 2: Covers root privilege management, daemon supervision via systemd, and secure file operations.
- ›Point 3: Applies to LTS releases (Ubuntu 24.04/22.04 LTS, Debian 12 Bookworm).
Enterprise Compatibility Update (2026 / LTS)
While these fundamentals apply directly to existing deployments, modern installations on Ubuntu 22.04 and 24.04 LTS use systemd-resolved, nftables for packet filtering, and modern OpenSSH 9+ with Ed25519 cryptography.
Why Multi-PHP Isolation is Vital
When managing production servers for hosting multiple web applications, legacy monoliths often require older runtimes (e.g., PHP 5.6 or 7.4) while newer microservices demand modern versions (PHP 8.2 / 8.3). Managing these conflicting runtimes on a single server without virtualization overhead requires dedicated PHP-FPM UNIX sockets mapped per VirtualHost.
Prerequisites & Baseline Setup
- ›One Linux server running Ubuntu 20.04 / 22.04 / 24.04 LTS or Debian 12.
- ›A user account with
sudoadministrative privileges. - ›Network connectivity with ports 80 (HTTP) and 443 (HTTPS) open.
127.0.0.1:9000).Step 1: Install Apache and mod_fcgid
Update your apt package cache and install Apache along with the FastCGI daemon module:
sudo apt update
sudo apt install -y apache2 libapache2-mod-fcgidStep 2: Install Multiple PHP-FPM Pools
Add the Ondřej Surý PHP repository to access all historical and modern PHP versions:
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt install -y php5.6 php5.6-fpm php7.4 php7.4-fpm/etc/php/<version>/fpm/pool.d/www.conf sets listen.owner = www-data and listen.group = www-data. If permissions mismatch, Apache will fail with 503 Service Unavailable.Verify that both PHP-FPM daemons are actively running:
sudo systemctl status php5.6-fpm
sudo systemctl status php7.4-fpmStep 3: Configure FastCGI and Proxy Modules
Enable the required proxy modules in Apache to communicate with UNIX sockets:
sudo a2enmod actions fcgid alias proxy_fcgiCreate isolated application document roots for testing both runtimes:
sudo mkdir -p /var/www/php56-app /var/www/php74-app
echo "<?php phpinfo(); ?>" | sudo tee /var/www/php56-app/index.php
echo "<?php phpinfo(); ?>" | sudo tee /var/www/php74-app/index.phpStep 4: Configure VirtualHosts with UNIX Sockets
Switch between the two site configurations below to inspect how each VirtualHost binds to its respective PHP socket:
<VirtualHost *:80>
ServerName php56.example.com
DocumentRoot /var/www/php56-app
<Directory /var/www/php56-app>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>Activate both sites and restart Apache:
sudo a2ensite php56.example.com
sudo a2ensite php74.example.com
sudo apache2ctl configtest
sudo systemctl restart apache2Step 5: Verify Multi-PHP Routing
Test both endpoints locally or by adding DNS host mappings to /etc/hosts:
curl -H "Host: php56.example.com" http://127.0.0.1/ | grep "PHP Version"
curl -H "Host: php74.example.com" http://127.0.0.1/ | grep "PHP Version"Each VirtualHost will independently execute through its designated PHP-FPM socket pool without runtime collision.
Ondřej Surý PHP PPA for Debian & Ubuntu
Official production Debian & Ubuntu packaging repository for modern and legacy PHP runtimes with FPM socket modules.

