I manage and maintain several web applications, but unfortunately some are still in CodeIgniter 3, which therefore stops at PHP version 8.0.30.
To be able to continue maintaining them, (despite the fact that this version of PHP is obsolete, and that the projects are migrated), it is necessary to make a small configuration in Apache, and to add the FPM packages.
It will be necessary to adapt, of course to your situation, as well as the folder containing the files and in the vhost directives.
First, add the repos GPG keys to the system, and add the repos URLs, and update the apt catalog.
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
Once done, install the desired versions of PHP-FPM
sudo apt install -y php8.0 php8.0-fpm php8.0-cli php8.0-common php8.0-curl php8.0-mbstring php8.0-xml php8.0-zip php8.0-gd
sudo apt install -y php8.4 php8.4-fpm php8.4-cli php8.4-common php8.4-curl php8.4-mbstring php8.4-xml php8.4-zip php8.4-gd
To check if the installation was successful, you can run the following commands. The PHP version should be displayed:
php8.0 -v php8.4 -v
Install Apache2 (if not already done), and activate the various necessary Apache modules and configurations
sudo apt install -y apache2
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.0-fpm
sudo a2enconf php8.4-fpm
sudo systemctl restart apache2
Now create the two folders that will contain the web projects
sudo mkdir /var/www/html/8.0
sudo mkdir /var/www/html/8.4
In the 000-default.conf file, overwrite the contents (if there are no special directives for your environment) and put the contents below:
ServerName localhost # Ou ton domaine par défaut
DocumentRoot /var/www/html
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
# Pour le sous-dossier PHP 8.0
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
SetHandler "proxy:unix:/var/run/php/php8.0-fpm.sock|fcgi://localhost/"
# Pour le sous-dossier PHP 8.4 (ou 8.x)
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
SetHandler "proxy:unix:/var/run/php/php8.4-fpm.sock|fcgi://localhost/"
# Optionnel : Un handler par défaut pour les autres dossiers (ex. PHP système)
SetHandler "proxy:unix:/var/run/php/php8.4-fpm.sock|fcgi://localhost/"
Save everything, and restart the Apache service
sudo systemctl restart apache2
And there you have it! Now if you go to http://localhost/8.0 and http://localhost/8.4, the projects will support the desired PHP version in those different folders.
For the CLI part (using PHP from the command line in the shell), only one can be set as default (in particular to use composer for example). To change the version, type the following command:
sudo update-alternatives --config php
Then choose the PHP version, and you're done.