Adding php8.3 as secondary ( not default ) module on Linux

This example shows how to install PHP 8.3 as a secondary PHP version on an Apache server without changing the system default PHP version. PHP 7.4 remains the default CLI version, while a specific website is configured to use PHP 8.3 through PHP-FPM.

Install PHP 8.3 FPM and Extensions

Install PHP 8.3 FPM together with the commonly required PHP extensions:

apt install php8.3-fpm php8.3-mysql php8.3-curl php8.3-gd php8.3-imagick php8.3-mbstring php8.3-xml php8.3-zip php8.3-intl php8.3-bcmath php8.3-soap php8.3-readline

During installation, PHP displays the following notice because Apache is already installed:

NOTICE: Not enabling PHP 8.3 FPM by default.
NOTICE: To enable PHP 8.3 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php8.3-fpm
NOTICE: You are seeing this message because you have the apache2 package installed.

Enable Apache FPM Modules

Enable the Apache modules required to communicate with PHP-FPM:

a2enmod proxy proxy_fcgi setenvif

There is no need to enable PHP 8.3 globally when only selected VirtualHosts should use it.

Keep PHP 7.4 as the Default CLI Version

Set PHP 7.4 as the default version used by the php command:

update-alternatives --set php /usr/bin/php7.4
update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in manual mode

This affects the command-line PHP interpreter. The Apache VirtualHost can still use PHP 8.3 independently through PHP-FPM.

Configure a VirtualHost to Use PHP 8.3

Add the following configuration under the DocumentRoot directive in the required Apache VirtualHost. In this example the configuration file is:

thesecretgarden.bg-le-ssl.conf

Add:

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

All PHP files for this VirtualHost will now be processed through the PHP 8.3 FPM socket:

/run/php/php8.3-fpm.sock

Restart Apache

Restart Apache to apply the configuration:

systemctl restart apache2

PHP 8.3 FPM Configuration

The main PHP configuration file used by PHP 8.3 FPM is:

/etc/php/8.3/fpm/php.ini

After changing this file, restart PHP-FPM and Apache for the changes to take effect:

systemctl restart php8.3-fpm
systemctl restart apache2

Result

PHP 7.4 remains the system default for CLI commands, while the selected Apache VirtualHost runs PHP files using PHP 8.3 FPM. This makes it possible to run websites requiring different PHP versions on the same Apache server.