Install multiple PHP versions with Apache on Debian

Update the repository cache.

sudo apt update
Install the below packages:
sudo apt install -y curl wget gnupg2 ca-certificates lsb-release apt-transport-https
Import the public using the below commands:
wget https://packages.sury.org/php/apt.gpg
sudo apt-key add apt.gpg
Add the sury repository to your system:
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php-sury.list
Update the repository index:
sudo apt update
Next install libapache2-mod-fcgid. This starts a number of CGI program instances to handle concurrent requests:
sudo apt install libapache2-mod-fcgid
Install PHP 5:
sudo apt install php5.6 php5.6-fpm php5.6-mysql libapache2-mod-php5.6
Install php 7:
sudo apt install php7.4 php7.4-fpm php7.4-mysql libapache2-mod-php7.4
Install PHP 8:
sudo apt install php8.2 php8.2-fpm php8.2-mysql libapache2-mod-php8.2
Once installed, you should have 3 new sockets in /var/run/php/
$ ls -la /var/run/php/*.sock
srw-rw---- 1 www-data www-data  0 Mar 12 18:29 /var/run/php/php5.6-fpm.sock
srw-rw---- 1 www-data www-data  0 Mar 12 18:30 /var/run/php/php7.4-fpm.sock
srw-rw---- 1 www-data www-data  0 Mar 12 18:30 /var/run/php/php8.2-fpm.sock
Start PHP-FPM Services:
sudo systemctl start php5.6-fpm
sudo systemctl start php7.4-fpm
sudo systemctl start php8.2-fpm
Configure Apache. We need to add some Apache modules using a2enmod:
sudo a2enmod actions fcgid alias proxy_fcgi
sudo systemctl restart apache2
Remove default files:
rm /etc/apache2/sites-enabled/000-default.conf
Create a new virtualhost at /etc/apache2/sites-enabled/php56.conf:
<VirtualHost *:80>
    ServerName www.examplephp56.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/php56
    >FilesMatch \.php>
        SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/" 
    </FilesMatch>
</VirtualHost>
Make test dirs:
mkdir -p /var/www/html/php56
and file /var/www/html/php56/info.php with contents:
<?php
phpinfo();
Add to /etc/hosts locally:
127.0.0.1 www.examplephp56.com
or on remote machine:
x.x.x.x www.examplephp56.com
where x.x.x.x is the IP address of machine where all was installed
Restart Apache:
systemctl restart apache2
and test using curl or browser if you are testing remotely:
curl www.examplephp56.com/info.php|grep ">PHP Version <"
For PHP 7 - procedure is the same, just use the following snippet
<FilesMatch \.php>
  SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/" 
</FilesMatch>
And for PHP 8:
<FilesMatch \.php>
  SetHandler "proxy:unix:/var/run/php/php8.2-fpm.sock|fcgi://localhost/" 
</FilesMatch>