Running sites on different versions of PHP on the same server

Thsi quick guide explains the steps needed to be able to run different versions of PHP on the same server (different virtual hosts or even different folders within the same site).


If the ‘add-apt-repository’ command is missing, you need to install the package “software-properties-common” first:

apt install -y software-properties-common

Add the ondrej/php repository to your system:

add-apt-repository ppa:ondrej/php

apt update:

apt update

Install Apache fastCGI module:

apt install -y libapache2-mod-fcgid

For each version of PHP

As of 1 Jan 2021, PHP versions 7.4 (php7.4) and 8.0 (php8.0) are those with active support and updates. PHP version 7.3 (php7.3) will continue to receive critical updates until 1 Jan 2022. See Supported PHP Versions.

Install required packages

apt install -y php7.4 php7.4-fpm php7.4-mysql libapache2-mod-php7.4

Install other wanted modules for the same PHP version, for example these commonly used:

apt-install -y php7.4-curl, php7.4-gd, php7.4-intl, php7.4-json, php7.4-mbstring, php7.4-readline

Start the php-fpm service:

systemctl start php7.4-fpm

Check that the service is running:

systemctl status php7.4-fpm

Configuring PHP version for virtual host or subfolder

Activate necessary Apache modules and restart Apache:

a2enmod actions fcgid alias proxy_fcgi
systemctl restart apache2

Use FilesMatch directive to set the PHP version:
FilesMatch is valid in both the virtualhost configuration and inside a Directory section.
To set PHP version globally for a virtual host, use it outside a Directory section.
The default PHP version can be set using ‘a2enmod php8.0’ (or any other version)

<FilesMatch \.php$>
  SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"

Check the configuration for errors:

apachectl configtest

If result is “Syntax OK”, restart Apache:

systemctl restart apache2


Create a file named ‘i.php’ in the locations with the different PHP versions (can be different virtualhosts or folders)


Access these locations on the virtualhosts or their directory locations to verify that they are using different PHP versions.


Most useful resource for this guide
How To Run Multiple PHP Versions on One Server Using Apache and PHP-FPM on Ubuntu 18.04 (DigitalOcean Community)

Detect if HTML5 video is playing or paused and show or hide a Div accordingly
Using files from web applications


Responsive IFRAMEs — The Right Way (CSS Only)!
How to Auto-resize an Image to Fit into a DIV Container using CSS

Everything You Need to Know About HTML’s ‘pre’ Element

CSS selector last row from main table

Google search – “html5 canvas layers transparency”

Tutorial: How To Style the HTML 5 Audio Player

Play local video file with HTML5

Use Fetch as Google for websites


PDF from every page of website

Google: php add protection to existing pdf

Custom colored Bootstrap button

Styling checkboxes

Border (darken background 10%)
Active (darken background 7.5%)

SSL certificate / VPN


Let’s Encrypt
How To Secure Apache with Let’s Encrypt on Ubuntu 20.04
Configuring Let’s Encrypt SSL Cert for Apache on Ubuntu 18.04
Let’s Debug

SSL for free



https on subdomain

SSL Server Test
How to disable outdated versions of SSL/TLS in Apache