Additional PHP versions on Debian | 3rd party integration
This guide explains how to install and configure multiple PHP versions on a Debian system using the SURY repository.
Contents
Important Note
This guide adds the SURY repository to install additional PHP packages and versions.
The SURY repository is a reputable repository by web hosting professionals worldwide, but IT'S NOT A OFFICIAL DEBIAN REPOSITORY. You have been warned.
Since packages like OpenSSL are also updated, the installed packages from sury.org cannot simply be removed after installation.
Do not remove SURY as a repository source later on. It will break your PHP installation
Note that PHP-FPM can be used on both Apache and Nginx servers, while FastCGI is available only for Apache servers.
Adding the SURY Repository
The extrepo way.
apt-get install extrepo extrepo enable sury
Or the manual way.
cd `mktemp -d` wget -q https://packages.sury.org/debsuryorg-archive-keyring.deb apt-get install ./debsuryorg-archive-keyring.deb . /etc/os-release cat << EOF > /etc/apt/sources.list.d/sury-php.sources Types: deb deb-src URIs: https://packages.sury.org/php Suites: $VERSION_CODENAME Components: main Signed-By: /usr/share/keyrings/debsuryorg-archive-keyring.gpg EOF apt-get update apt-cache policy php
Installing Additional PHP Versions
You don't need to install every version listed below. Install only the versions you need for your specific use case.
PHP 5.6
sudo apt install php5.6 php5.6-cli php5.6-cgi php5.6-fpm
PHP 7.0
sudo apt install php7.0 php7.0-cli php7.0-cgi php7.0-fpm
PHP 7.1
sudo apt install php7.1 php7.1-cli php7.1-cgi php7.1-fpm
PHP 7.2
sudo apt install php7.2 php7.2-cli php7.2-cgi php7.2-fpm
PHP 7.3
sudo apt install php7.3 php7.3-cli php7.3-cgi php7.3-fpm
PHP 7.4
sudo apt install php7.4 php7.4-cli php7.4-cgi php7.4-fpm
PHP 8.0
sudo apt install php8.0 php8.0-cli php8.0-cgi php8.0-fpm
PHP 8.1
sudo apt install php8.1 php8.1-cli php8.1-cgi php8.1-fpm
PHP 8.2
sudo apt install php8.2 php8.2-cli php8.2-cgi php8.2-fpm
PHP 8.3
sudo apt install php8.3 php8.3-cli php8.3-cgi php8.3-fpm
PHP 8.4
sudo apt install php8.4 php8.4-cli php8.4-cgi php8.4-fpm
Configuring the Default PHP Version
After installing additional PHP versions, if you want to set the OS default PHP version back to the one for your Debian release, run these commands:
update-alternatives --config php
update-alternatives --config php-cgi
If you want to select the appropriate default version of your Debian release:
- Debian 12: default version is PHP 8.2
- Debian 11: default version is PHP 7.4
- Debian 10: default version is PHP 7.3
Using Multiple PHP Versions
After installing and configuring multiple PHP versions, you can specify which version to use on a per-website basis through your web server configuration. This guide doesn't cover web server configuration, just different PHP versions installations concurrently.
For manual configuration:
For Apache with mod_php: You can use different ?VirtualHost configurations for different PHP versions concurrently
- For Apache with FastCGI: Configure different PHP handlers in your Apache configuration
- For Nginx with PHP-FPM: Configure different PHP-FPM pools in your Nginx server blocks
Troubleshooting
If you encounter issues with the installation or configuration of multiple PHP versions, ensure that:
- The correct paths are configured for PHP binaries and configuration directories
- Web server configurations are properly pointing to the correct PHP version
For more help, consult the PHP documentation or the Debian forums.
See Also