How to install PHP 5.6 as additional PHP-FPM & FastCGI for ISPConfig 3.1 on Ubuntu 16.04

This tutorial shows how to build PHP 5.6 as a PHP-FPM and a FastCGI version on Ubuntu 16.04 (Xenial Xerus). Ubuntu 16.04 ships with PHP 7 by default but there are still many websites out there that don't support PHP 7. This tutorial will show you how to install PHP 5.6 as additional PHP version on Ubuntu 16.04 so that you can switch between both versions for each website individually in ISPConfig.

 

1 Preliminary Note

I will install PHP 5.6 in /opt so that the main PHP 7 of Ubuntu is not affected and PHP 7 will stay the default PHP of our server while PHP 5.6 is available as option in ISPConfig (website settings). Please note that PHP-FPM can be used on both Apache and Nginx servers while FastCGI is available only for Apache servers in ISPConfig.

With older PHP versions, PHP-FPM and FastCGI had been mutually exclusive so that an FPM and FastCGI binary had to be build separately. With PHP 5.6, a single binary that supports FPM and FCGI mode can be build.

 

2 Compile PHP 5.6 with PHP-FPM and Fastcgi

Install the prerequisites to build PHP 5.6, wget and the nano editor that I will use to edit the config files:

apt-get install build-essential wget nano

apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev

ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a

(The last command is needed if you build PHP with --with-imap, because otherwise ./configure will stop with the following error:

checking for crypt in -lcrypt... yes
configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.
[email protected]:/usr/local/src/php5-build/php-5.6.25#

)

Download and extract PHP 5.6 from php.net:

mkdir /opt/php-5.6.25
mkdir /usr/local/src/php5-build
cd /usr/local/src/php5-build
wget http://de.php.net/get/php-5.6.25.tar.bz2/from/this/mirror -O php-5.6.25.tar.bz2
tar jxf php-5.6.25.tar.bz2

cd php-5.6.25/

Configure and build PHP 5.6.25 as follows (you can adjust the ./configure command to your needs, take a look at

./configure --help

to see all available options; if you use a different ./configure command, it is possible that additional libraries are required, or the build process will fail):

./configure --prefix=/opt/php-5.6.25 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap --with-imap-ssl --with-gettext --with-xmlrpc --with-xsl --with-kerberos --enable-fpm

The above string is just one long command, do not add any line breaks. The last switch (--enable-fpm) makes sure this PHP version will work with PHP-FPM.

make
make install

Copy php.ini and php-fpm.conf to the correct locations:

cp /usr/local/src/php5-build/php-5.6.25/php.ini-production /opt/php-5.6.25/lib/php.ini

cp /opt/php-5.6.25/etc/php-fpm.conf.default /opt/php-5.6.25/etc/php-fpm.conf

Create the pool file directory php-fpm.d.

mkdir /opt/php-5.6.25/etc/php-fpm.d

Open /opt/php-5.6.25/etc/php-fpm.conf and adjust the following setting (remove the ; in front of the pid line):

nano /opt/php-5.6.25/etc/php-fpm.conf

[...]
pid = run/php-fpm.pid
[...]
user = www-data
group = www-data
[...]
listen = 127.0.0.1:8999
[...]
include=/opt/php-5.6.25/etc/php-fpm.d/*.conf

3 Create the systemd unit file

Ubuntu 16.04 uses systemd as init system. I will create a systemd unit file to be able to start / stop and restart the PHP-FPM service.

nano /lib/systemd/system/php-5.6.25-fpm.service

with the following content:

[Unit]
Description=The PHP 5.6 FastCGI Process Manager
After=network.target

[Service]
Type=simple
PIDFile=/opt/php-5.6.25/var/run/php-fpm.pid
ExecStart=/opt/php-5.6.25/sbin/php-fpm --nodaemonize --fpm-config /opt/php-5.6.25/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

Enable the service and reload systemd:

systemctl enable php-5.6.25-fpm.service
systemctl daemon-reload

Finally start PHP-FPM.

systemctl start php-5.6.25-fpm.service

To enable the Zend OPcache, open /opt/php-5.6.25/lib/php.ini...

nano /opt/php-5.6.25/lib/php.ini

... and add the following line at the end:

[...]
zend_extension=opcache.so

Test the PHP version:

cd /opt/php-5.6.25/bin
./php --version

The output should be similar to this screenshot.

4 Enable PHP 5.6 in ISPConfig

In ISPConfig 3.1, you can configure the new PHP version under System > Additional PHP Versions. On the Name tab, you just fill in a name for the PHP version (e.g. PHP 5.6.25) - this PHP version will be listed under this name in the website settings in ISPConfig:

Add PHP 5.6 in ISPConfig

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

Path to the PHP FastCGI binary: /opt/php-5.6.25/bin/php-cgi
Path to the php.ini directory: /opt/php-5.6.25/lib

PHP-FCGI settings

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

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

PHP-FPM settings

Share this page:

7 Comment(s)

Add comment

Comments

From: Gino Carpanetti D. at: 2016-09-25 04:03:03

 Hello and thanks for the tutorial, worked perfect and i needed to add and older version of php to my ispconfig.

I'm having trouble with increasing the upload_max_filesize.

I changes the php.ini in opt/php-5.6.25/lib/php.ini wich is the location, acording to phpinfo(); from where the system is loading the configuration.

I change the parameter but nothing happens.

Bye and thanks

From: till at: 2016-09-25 15:36:22

Did you restart php-fpm after you changed the php.ini?

systemctl restart php-5.6.25-fpm.service

From: Henning at: 2016-10-10 06:30:02

On a fresh Ubuntu 16.04 I used the automated install for ISPConfig with Nginx. Then I used this tutorial. After creating a website and assigning the additional php version (5.6.25) I receive error 502. The log for the site says the following:

2016/10/09 08:08:22 [crit] 3906#3906: *5 connect() to unix:/var/lib/php7.0-fpm/web1.sock failed (2: No such file or directory) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.domain.de, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/lib/php7.0-fpm/web1.sock:", host: "xxx.domain.de"

So it seems php 5.6 is not used. However I the whole process several times and I am pretty sure I obeyed every single step. Do you have any suggestion where to look to get it running?

From: Henning at: 2016-10-10 07:13:39

Please remove my former comment. I had a typo in the path to php-fpm.conf. I apologize for not being careful enough...

From: Marian at: 2016-10-20 17:39:54

Hello. Thanks a lot for this useful tutorial, I follow step by step instructions and the magic happends, now I have php 7 and php 5.6.25 available (on Ubuntu server 16.04 with ISPConfig). Very useful and understandable tutorial.

From: Rafael Santana at: 2016-10-27 13:03:50

IS working in debian 8?

From: Luis Muzquiz at: 2016-11-10 02:05:43

How can i connect apache2 and libapache2-mod-fastcgi to this php-fpm 5.6 without step 4 (without enabling PHP 5.6 in ISPConfig). Is there another way to enable php-fpm?

I get the correct result when using: ./php --version but how can i get php version just using php -v?