Running Multiple Different PHP Versions Simultaneously on Ubuntu 24.04
If you need to run multiple different versions of PHP simultaneously on your Ubuntu server, it can be done. This is needed when you want to host some legacy sites that cannot run with the breaking changes made in the newest versions of PHP (shame on you PHP for doing such nonsense).
Here's how I did it on an Ubuntu 24.04 server which uses PHP 8.3 by default. In this example, I have already installed and configured all web server software packages including PHP 8.3. The EHCP Force installer can do this for you if you don't know how to install and configure everything you need to run your own web server.
Add the ondrej repo and install PHP 5.6 and 7.4:
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt upgrade
sudo apt-get install php5.6 php5.6-fpm php7.4 php7.4-fpm
sudo apt-get install php7.4-mysql php5.6-mysql php5.6-mysqlnd-ms php7.4-gd php5.6-gd php5.6-zip php7.4-zip php7.4-cli php5.6-cli php5.6-mcrypt php7.4-mcrypt php7.4-gettext php5.6-gettext php5.6-mailparse php7.4-mailparse php7.4-imagick php5.6-imagick php5.6-curl php7.4-curl php7.4-xmlrpc php5.6-xmlrpc php5.6-imap php7.4-imap
I then adjusted the fpm php.ini files in the /etc/php/5.6/fpm/ and /etc/php/7.4/fpm directories to use custom settings that I use (optional). I then edited the FPM pool for each version of PHP in the www.conf file in /etc/php/7.4/fpm/pool.d and /etc/php/5.6/fpm/pool.d directories to listen on a different port than PHP 8.3. For example, for PHP 7.4, I changed the listen port to 9011.
Then, for the particular website I wanted to run under a different version of PHP, I changed the nginx template to use the corresponding port for the desired PHP FPM version like so:
location ~ \.php$ {
root {homedir}/httpdocs;
include fastcgi_params;
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9011;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE "open_basedir={homedir}:/usr/share/php:/usr/share/pear \n upload_tmp_dir={homedir}/phptmpdir \n session.save_path={homedir}/phptmpdir";
fastcgi_read_timeout 300;
limit_req zone=one burst=5;
}
Restart nginx. The website you configured to use a specific version of PHP will be using that version now.