How to install PHP 7.x as PHP-FPM & FastCGI for ISPConfig 3.1 with apt on Debian 8 and 9

The final version of PHP 7.1 is available now. PHP 7.1 is the next generation of the PHP programming language, it is up to 2 times faster than PHP 5.6 and 14 times faster than PHP 5.0 according to the release notes. The new PHP version is not 100% compatible with PHP 5.x as some deprecated API's have been removed, so it is a good idea to start testing your web sites for compatibility with this new release. This can be done easily and without affecting all sites on your server by using the multi PHP version feature in ISPConfig 3. The PHP version can be selected in the ISPConfig 3 website settings for each site individually. This feature works with PHP-FPM and FastCGI. This tutorial shows how to install PHP 7.x as a PHP-FPM and a FastCGI version on a Debian Jessie or Stretch server from the Debian PHP Package maintainers site directly.

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:

Enter the name of the custom PHP version

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

PHP 7.1 FastCGI

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

PHP 7.1 FPM settings

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 shure 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: php-fpm5.6
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: php-fpm7.0
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: php-fpm7.1
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.

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 this command:

apt-get install apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt-get update

Only packages for Debian 8 (Jessie) and Debian 9 (Stretch) are available, do not use it for other releases!

To 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

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

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

5.4 Install the lastest PHP version

To install the lastest PHP version use this command:

apt-get install php php-cli php-cgi php-fpm

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 Install other extensions (optional)

There are a lot of additional extensions you can install for PHP. Here is a list of available packages, some of them you have to install for each version separately. Simply delete packages you are not going to use from the following commands:

9.1 Version independent packages

apt-get install

9.2 Version dependent packages

apt-get install

10 Restart FPM daemon

Finally restart the php-fpm daemon, run the commands for the previously installed ones:

service php5.6-fpm restart

service php7.0-fpm restart

service php7.1-fpm restart

Share this page:

Suggested articles

12 Comment(s)

Add comment

Comments

From: Nicholas at: 2017-07-11 15:01:51

Plz for centos?!

From: Karl at: 2017-07-11 20:39:40

Will ISP config create phpfpm pools for each website as different user?

From: till at: 2017-07-12 06:35:01

yes

From: Arek at: 2017-07-12 09:42:20

1. Is point 9 completed? 9.1 and 9.2 look the same...

2. Point 6 - If I have memcache installed from default debian repos, will not this make conflict?

3. After install php7.0 and php7.1 on debian jessie with default 5.6 installed ISPConfig 3.1 stop work. Log: WARNING - There is already a lockfile set, but no process running with this pid (11667). Continuing.

Class 'mysqli' not found in /usr/local/ispconfig/server/lib/classes/db_mysql.inc.php on line 30

I think install command should include php7.0-mysql too.After install php in /etc/alternatives was changed to php7.1 and ISPConfig has problem with this. 

From: Ruben at: 2017-07-12 12:08:39

The article needs huge improvement.

There are some points which are not finished and it caused trouble, but I have fixed it.

 

You need to change the fpm init script (if applicable) to:

php5.6-fpm

php7.0-fpm

php7.1-fpm

 

And you need to install some packages:

phpX.X-mysql and phpX.X-mbstring

 

These websites have helped me:

HowtoForge discussion

Another website

From: Ruben at: 2017-07-12 11:46:48

I think that paths to FPM init scripts are wrong. Those are what I have in my server:

 

php5.6-fpm

php7.0-fpm

php7.1-fpm

From: Plamen Vasilev at: 2017-07-12 21:13:11

Please add in article and php 7.2:

apt-get install php7.2 php7.2-cli php7.2-cgi php7.2-fpm

From: Tiago at: 2017-07-12 22:25:48

Can I use this tutorial in Ubuntu 14.04?

From: Plamen Vasilev at: 2017-07-12 22:28:45

Please add in article and commands after install php7.1 or/and php7.2:

update-alternatives --config phpupdate-alternatives --config php-fpmupdate-alternatives --config php-cgi

and select debian default version (5.6 for Jessie, 7.0 for Stretch)

because if lastest installed version is php7.1 (for example) - /usr/bin/php -v shown:

 $ php -vPHP 7.1.7-1+0~20170711133214.5+stretch~1.gbp5284f4 (cli)

From: gOOvER at: 2017-07-16 07:01:22

After installing php7.1 it's needed to set in Debian 9:

update-alternatives --config php

update-alternatives --config php-cgi

 

manuell to 7.0. Else ispconfig3 will not start end ends in an Error 500

From: gOOvER at: 2017-07-16 07:37:51

Update: On Debian 9 i must reinstall a lot of packages:

apt-get install php-zip php-zeroc-ice php-xml php-tcpdf php-ssh2 php-soap php-snmp php-redis php-php-gettext php-mysql php-pear php-net-smtp php-net-socket php-net-imap php-net-nntp php-mcrypt php-mbstring php-imap php-intl php-json php-imagick php-gnupg php-gd php-geoip php-fpm php-dev php-mail php-mail-mime php-curl php-cli php-cgi php-bz2 php-bcmath php-apcu php-auth-sasl php-apcu-bc php7.1-common php7.0-common php5.6-common php7.1-opcache php7.0-opcache php5.6-opcache php7.1-mysql php7.0-mysql php5.6-mysq

From: Oitsuki at: 2017-07-18 02:52:08

Hello,

After installer php 7.1, I have been this error PHP Fatal error:  Uncaught Error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'

/etc/php/7.1 I haven"t apache2 /etc/php/7.1/cgi/php.ini  : do something must make ?

My version php 7.0 works fine I go back but i would know why the 7.1 does'nt wok/etc/php/7.0  : I have apache2 not in 7.1