Install multiple version of PHP
In this guide we are going to see how to install multiple version of PHP different from the one shipped with Debian. At the moment of writing current Debian version (12) is shipped with PHP 8.
Adding repository
Because on the official Debian repository only one version is available we need to add an alternative repository that contains the missing once. In this guide we are going to use ondrej/php ppa (via sury packages).
First things we need to install requirements so we are going to use:
Now we need to retrieve repository signing key. We can do this with the following command:
Then as last step we can add the repository as follows:
Installing packages
Now that we have added ondrej/php repos we can finally refresh packages list with:
As last step we can install the desired php version. Is important to indicate specific version of PHP desired. We can install following this packages name schema:
Where X is the main version of php (e.g. 5,7,8) and Y the subversion (for example for php 7.3 will be 3). In the end we need to specify with packages we want.
- Warning!
If are going to install a packages that require php as dependencies is possible that APT wil try to install the latest version available beside the one already installed. To mitigate this issue you can switch to the desired fpm engine on your webserver.