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

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

Embed docs directly on your website with a few lines of code

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

11 Links

Source

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.