HowtoForge

How to install PHP 5.6 and 7.0 - 7.4 as PHP-FPM & FastCGI for ISPConfig 3.1 with apt on Debian 8 to 10

This tutorial shows how to install multiple PHP versions on an ISPConfig Debian server. The PHP version can later be selected in the ISPConfig 3 website settings for each site individually. This feature works with PHP-FPM and FastCGI. We will install PHP 5.6 and 7.x as a PHP-FPM and a FastCGI version on a Debian server by using the PHP packages from sury.org.

1 Preliminary Note

I will install PHP directly from Debian PHP Package maintainers site https://packages.sury.org/php/ with apt-get. This will not overwrite the existing installation but will change the default used PHP version to the newest installed one! So it is very important to add a new PHP version for the installed version to ISPConfig and change all sites to this version first. If you are using cron jobs calling PHP scripts you have to adapt them too, later more on that.

Because other packages as openssl are updated too, the installed packages from sury.org can not simply removed after installation. You first have to downgrade this packages to the Debian versions before you are able to remove the PHP packages without breaking other packages. The simplest way for me was to deactivate the new added repository, then installed packages from sury.org will apear as self created or deprecated packages in aptitude and you are able to downgrade package after package.

Please note that PHP-FPM can be used on both Apache and Nginx servers while FastCGI is available for Apache servers only.

2 Enable PHP versions in ISPConfig

In ISPConfig 3, you can configure the new PHP versions under System > Additional PHP Versions.

Add Debian's PHP version

You can skip this step if you do not have a Debian version of PHP installed.

First of all you have to add a new version for the already installed PHP version. On the Name tab, you just fill in a name for the PHP version (e.g. Debian 5.6) - this PHP version will be listed under this name in the website settings in ISPConfig:

Go to the FastCGI Settings tab and fill out the fields as follows:

Path to the PHP FastCGI binary: php5-cgi
Path to the php.ini directory: /etc/php5/cgi/php.ini

Then go to the PHP-FPM Settings tab and fill out the fields as follows:

Path to the PHP-FPM init script: php5-fpm
Path to the php.ini directory: /etc/php5/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php5/fpm/pool.d

Important step for cron jobs

If you use cron jobs calling PHP scripts you also have to tell cron which version to use. Add php5 in the beginning of the command to use the Debian's version. If you are not sure what you exactly are using follow the symlink /usr/bin/php and use its final destination as prefix.

Add other PHP versions

Currently there are 3 versions available at https://packages.sury.org/php/ and you have to repeat the last step now for every version you will install. But use the following settings instead:

PHP 5.6

Path to the PHP FastCGI binary: php-cgi5.6
Path to the php.ini directory: /etc/php/5.6/cgi/php.ini
Path to the PHP-FPM init script: php5.6-fpm
Path to the php.ini directory: /etc/php/5.6/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/5.6/fpm/pool.d

The cli version for e.g. cron jobs has the name php5.6.

PHP 7.0

Path to the PHP FastCGI binary: php-cgi7.0
Path to the php.ini directory: /etc/php/7.0/cgi/php.ini
Path to the PHP-FPM init script: php7.0-fpm
Path to the php.ini directory: /etc/php/7.0/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.0/fpm/pool.d

The cli version for e.g. cron jobs has the name php7.0.

PHP 7.1

Path to the PHP FastCGI binary: php-cgi7.1
Path to the php.ini directory: /etc/php/7.1/cgi/php.ini
Path to the PHP-FPM init script: php7.1-fpm
Path to the php.ini directory: /etc/php/7.1/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.1/fpm/pool.d

The cli version for e.g. cron jobs has the name php7.1.

PHP 7.2

Path to the PHP FastCGI binary: php-cgi7.2
Path to the php.ini directory: /etc/php/7.2/cgi/php.ini
Path to the PHP-FPM init script: php7.2-fpm
Path to the php.ini directory: /etc/php/7.2/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.2/fpm/pool.d

The cli version for e.g. cron jobs has the name php7.2.

PHP 7.3

Path to the PHP FastCGI binary: php-cgi7.3
Path to the php.ini directory: /etc/php/7.3/cgi/php.ini
Path to the PHP-FPM init script: php7.3-fpm
Path to the php.ini directory: /etc/php/7.3/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.3/fpm/pool.d

The cli version for e.g. cron jobs has the name php7.3.

PHP 7.4

Path to the PHP FastCGI binary: php-cgi7.4
Path to the php.ini directory: /etc/php/7.4/cgi/php.ini
Path to the PHP-FPM init script: php7.4-fpm
Path to the php.ini directory: /etc/php/7.4/fpm/php.ini
Path to the PHP-FPM pool directory: /etc/php/7.4/fpm/pool.d

The cli version for e.g. cron jobs has the name php7.4.

3 Change PHP version of websites

You can skip this step if you do not have a Debian version of PHP installed.

Now change the PHP version of all websites to the newly created version (e.g. Debian 5.6).

And do not forget to change the cron jobs as mentioned above.

4 Add the repository at packages.sury.org

To add the repository at packages.sury.org and its BGP keys to apt use these commands:

apt-get install -y apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

The next command is just one line, don't add any line breaks:

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt-get update

To upgrade already installed packages from the new repository use this command:

apt-get upgrade

5 Install PHP from packages.sury.org

I am offering here multiple options to install, please pick the desired versions and simply skip the rest!

5.1 Install PHP 5.6

To install PHP use this command:

apt-get install php5.6 php5.6-cli php5.6-cgi php5.6-fpm php5.6-gd php5.6-mysql php5.6-imap php5.6-curl php5.6-intl php5.6-pspell php5.6-recode php5.6-sqlite3 php5.6-tidy php5.6-xmlrpc php5.6-xsl php5.6-zip php5.6-mbstring php5.6-soap php5.6-opcache libicu65 php5.6-common php5.6-json php5.6-readline php5.6-xml

5.2 Install PHP 7.0

To install PHP use this command:

apt-get install php7.0 php7.0-cli php7.0-cgi php7.0-fpm php7.0-gd php7.0-mysql php7.0-imap php7.0-curl php7.0-intl php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-zip php7.0-mbstring php7.0-soap php7.0-opcache php7.0-common php7.0-json php7.0-readline php7.0-xml

5.3 Install PHP 7.1

To install PHP use this command:

apt-get install php7.1 php7.1-cli php7.1-cgi php7.1-fpm php7.1-gd php7.1-mysql php7.1-imap php7.1-curl php7.1-intl php7.1-pspell php7.1-recode php7.1-sqlite3 php7.1-tidy php7.1-xmlrpc php7.1-xsl php7.1-zip php7.1-mbstring php7.1-soap php7.1-opcache php7.1-common php7.1-json php7.1-readline php7.1-xml

5.4 Install PHP 7.2

To install PHP use this command:

apt-get install php7.2 php7.2-cli php7.2-cgi php7.2-fpm php7.2-gd php7.2-mysql php7.2-imap php7.2-curl php7.2-intl php7.2-pspell php7.2-recode php7.2-sqlite3 php7.2-tidy php7.2-xmlrpc php7.2-xsl php7.2-zip php7.2-mbstring php7.2-soap php7.2-opcache php7.2-common php7.2-json php7.2-readline php7.2-xml

5.5 Install PHP 7.3

To install PHP use this command:

apt-get install php7.3 php7.3-cli php7.3-cgi php7.3-fpm php7.3-gd php7.3-mysql php7.3-imap php7.3-curl php7.3-intl php7.3-pspell php7.3-recode php7.3-sqlite3 php7.3-tidy php7.3-xmlrpc php7.3-xsl php7.3-zip php7.3-mbstring php7.3-soap php7.3-opcache php7.3-common php7.3-json php7.3-readline php7.3-xml

5.6 Install PHP 7.4

To install the lastest PHP version use this command:

apt-get install php7.4 php7.4-cli php7.4-cgi php7.4-fpm php7.4-gd php7.4-mysql php7.4-imap php7.4-curl php7.4-intl php7.4-pspell php7.4-sqlite3 php7.4-tidy php7.4-xmlrpc php7.4-xsl php7.4-zip php7.4-mbstring php7.4-soap php7.4-opcache libonig5 php7.4-common php7.4-json php7.4-readline php7.4-xml

6 Install Memcache extension (optional)

To install Memcache use this command:

apt-get install php-memcache php-memcached

7 Install APCu extension (optional)

To install APC user cache use this command:

apt-get install php-apcu php-apcu-bc

8 Install xDebug extension (optional)

The xDebug module is a debugging extension for PHP. The installation is optional.

To install xDebug use this command:

apt-get install php-xdebug

This package seems to have other default settings than the Debian package php5-xdebug. Depending on your software you have to change settings like xdebug.max_nesting_level to get it running!

9 Set Debian default PHP back to the original version

The default PHP of the operating system has to remain at the original version. To fix that, run these commands:

update-alternatives --config php
update-alternatives --config php-cgi

On Debian 10, choose 7.3, on Debian 9: Choose PHP 7.0, on Debian 8, choose PHP 5.6 in the dialog that appears.

10 Restart FPM daemon

Finally, restart the php-fpm daemons. Run the commands for the previously installed ones:

service php5.6-fpm restart
service php7.0-fpm restart
service php7.1-fpm restart
service php7.2-fpm restart
service php7.3-fpm restart
service php7.4-fpm restart
How to install PHP 5.6 and 7.0 - 7.4 as PHP-FPM & FastCGI for ISPConfig 3.1 with apt on Debian 8 to 10