There is a new revision of this tutorial available for Debian 8 (Jessie).

How to install PHP 7 (PHP-FPM & FastCGI) for ISPConfig 3 on Debian 8 (Jessie)

The first Beta of PHP 7 is available for download now, PHP 7 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 build the new PHP 7 (Beta) as a PHP-FPM and a FastCGI version on a Debian Jessie server. These PHP 7 builds include Zend OPcache.

 

Preliminary Note

I will install PHP 7 that is currently in Beta at the time of this writing. Please note that PHP-FPM can be used on both Apache and nginx servers, while FastCGI is available only for Apache servers.

With older PHP versions, PHP-FPM and FastCGI had been mutually exclusive so that a fpm and FastCGI binary had been build separately. With PHP 7, both binaries can be build together, so we will have to do just one PHP build now.

 

Compile PHP 7 with PHP-FPM and Fastcgi

Download and extract PHP 7:

mkdir -p /opt/php-7.0.0
mkdir /usr/local/src/php5-build
cd /usr/local/src/php5-build
wget https://downloads.php.net/~ab/php-7.0.0beta1.tar.bz2 -O php-7.0.0.tar.bz2
tar jxf php-7.0.0.tar.bz2

cd php-7.0.0beta1/

Install the prerequisites for building PHP 7 and the nano editor that I will use to edit the config files:

apt-get install build-essential nano

apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-turbo-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-7.0.0#

)

Configure and build PHP 7.0.0 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-7.0.0 --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-mysqli --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-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm

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-7.0.0beta1/php.ini-production /opt/php-7.0.0/lib/php.ini

cp /opt/php-7.0.0/etc/php-fpm.conf.default /opt/php-7.0.0/etc/php-fpm.conf
cp /opt/php-7.0.0/etc/php-fpm.d/www.conf.default /opt/php-7.0.0/etc/php-fpm.d/www.conf

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

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

[...]
pid = run/php-fpm.pid
[...]

Then open /opt/php-7.0.0/etc/php-fpm.conf and adjust the listen line, you must use an unused port (e.g. 8999; port 9000 might be in use by Debian's default PHP-FPM already):

nano /opt/php-7.0.0/etc/php-fpm.d/www.conf

[...]
listen = 127.0.0.1:8999
[...]

Debian supports Systemd as well as the traditional init scripts. First I will create an init script for the php-fpm service and then I will create a systemd unit.

First create an init script for PHP-FPM:

nano /etc/init.d/php-7.0.0-fpm

#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-7.0.0-fpm
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-7.0.0-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO
php_fpm_BIN=/opt/php-7.0.0/sbin/php-fpm
php_fpm_CONF=/opt/php-7.0.0/etc/php-fpm.conf
php_fpm_PID=/opt/php-7.0.0/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF"
wait_for_pid () {
        try=0
        while test $try -lt 35 ; do
                case "$1" in
                        'created')
                        if [ -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                        'removed')
                        if [ ! -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                esac
                echo -n .
                try=`expr $try + 1`
                sleep 1
        done
}
case "$1" in
        start)
                echo -n "Starting php-fpm "
                $php_fpm_BIN $php_opts
                if [ "$?" != 0 ] ; then
                        echo " failed"
                        exit 1
                fi
                wait_for_pid created $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;
        stop)
                echo -n "Gracefully shutting down php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -QUIT `cat $php_fpm_PID`
                wait_for_pid removed $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed. Use force-exit"
                        exit 1
                else
                        echo " done"
                       echo " done"
                fi
        ;;
        force-quit)
                echo -n "Terminating php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -TERM `cat $php_fpm_PID`
                wait_for_pid removed $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;
        restart)
                $0 stop
                $0 start
        ;;
        reload)
                echo -n "Reload service php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -USR2 `cat $php_fpm_PID`
                echo " done"
        ;;
        *)
                echo "Usage: $0 {start|stop|force-quit|restart|reload}"
                exit 1
        ;;
esac

Make the init script executable and create the system startup links:

chmod 755 /etc/init.d/php-7.0.0-fpm
insserv php-7.0.0-fpm

And now create the systemd unit file

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

with the follwoing content:

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

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

[Install]
WantedBy=multi-user.target

And reload systemd:

systemctl daemon-reload

Finally start PHP-FPM.

For systems with traditional init system, run:

/etc/init.d/php-7.0.0-fpm start

The result should be:

/etc/init.d/php-7.0.0-fpm start
Starting php-fpm done

On servers that use systemd, use this command instead:

systemctl start php-7.0.0-fpm.service

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

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

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

[...]
zend_extension=opcache.so

The memcache and APCu extension can not be installed on PHP 7 yet, so I will skip their installation for now. I will update the tutorial later when the pecl extensions are compatible with PHP 7.

Enable PHP 7 in ISPConfig

In ISPConfig 3, 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 7.0.0) - 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: /opt/php-7.0.0/bin/php-cgi
Path to the php.ini directory: /opt/php-7.0.0/lib

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

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

 

Share this page:

17 Comment(s)

Add comment

Comments

From: rober

Hi!

This Guide work also with Ubuntu 15.04?

From: till

Yes, I think it should work for the latest Ubuntu version as well.

From: Joern

It dont work for me. Installed it without error, but if I want to choose it in ISPconfig, it just jumps back to default if I want to safe the selected PHP Option :(

From: Sunil

how to update php7.0.0 beta1 beta2 with php7.0.0? Thank you

From: till

Red the same steps with 7.0 final.

From: DjYXA

the ./configure option has --with-mysqli two times.. Change the first --with-mysqli with --with-mysql like this:

./configure --prefix=/opt/php-7.0.0 --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-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm

From: Andreas

I've followed this tutorial on a basically fresh install of Debian 8 and ISPConfig 3 and seen that I lack mysql support aside mysqli. So I changed the configure command options as someone pointed out here just to get

configure: WARNING: unrecognized options: --with-mysql

 

Any ideas?

 

I'm trying to run Textpattern which still has mysql, not mysqli..

From: Madalin Ignisca

Hello Andreas.

The MySQL extension has been removed from PHP 7: http://php.net/manual/en/function.mysql-info.php

To have the old extension, you should use the latest version of PHP 5.4 for best support with it.

You could use multiple PHP versions very easy and with ISPConfig's help or even manually.

From: Marek

Its bad becose ispconfig still generate conf file with socket system, which goes to 502 Bad Gateway. Is there any solution with php 7 and socket system instead of pool listening?

From: till

ISPConfig supports both modes, socket and port and the PHP 7 configuration above works in ispconfig with socket and port mode.

From: Mtx

Hello. Thanks a lot for this tutorial, really comprehensive. 

I'm using it to setup PHP7 with nginx server. And those words make me ask this question "Please note that PHP-FPM can be used on both Apache and nginx servers, while FastCGI is available only for Apache servers.".

With PHP 5.x, i was using PHP-fpm with fastCGI to process PHP scripts (from my nginx conf files). But with those words, i dont know if I'll be able to.

So following this, i'll not be able to use fastCGI socket to pass my PHP script ? Do we need to wait for PHP7 final build ?

thanks a lot !

 

From: till

The current PHP 7 release will work for nginx setups as well.

From: Jürgen Dorn

Hi, thanks for your guide but I had issue to establish a database connection using PHP 7 , maybe due to usign mariadb, from what I found in the apache logs. So I configured using the correct header paths

--with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr

finally looks like:

./configure --prefix=/opt/php-7 --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-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr --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-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm

 

From: Thomas

Hi, I tried to add php7 as an additional php version on my server. It runs on Ubunto 14.04.3 LTS and the latest version of ISPConfig3. All packages are up to date.

I followed the tutorial until step

insserv php-7.0.0-fpm

and used

update-rc.d php-7.0.0-fpm defaults

/etc/init.d/php-7.0.0-fpm start

instead.

But now I run in to the following error:

-bash: /etc/init.d/php-7.0.0-fpm: /bin/sh^M: bad interpreter: No such file or directory

Does someone have an Idea, where I went wrong?

Cheers and Happy Holidays!

From: till

Checj the init file that you created, it seems as if it contains windows linebreaks ^M instead of Linux linebreaks.

From: DjYXA

Change the fpm sock for this in nginx conf -> fastcgi_pass 127.0.0.1:8999;

And... voilá, fastCGI on nginx Ó_ò

From: gdecris

Would it be possible to add a status to the service commands? besides that this is great