How to install PHP 7 as PHP-FPM & FastCGI for ISPConfig 3 on Debian 8 (Jessie)
This tutorial exists for these OS versions
- Debian 9 (Stretch)
- Debian 8 (Jessie)
- Debian 8 (Jessie)
- Debian 8 (Jessie)
On this page
The final version of PHP 7 is available for download on Github and the PHP mirrors now. PHP7 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 build the new PHP 7 as a PHP-FPM and a FastCGI version on a Debian Jessie server. These PHP 7 builds include Zend OPcache.
1 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 an FPM and FastCGI binary had to be built separately. With PHP 7, a single binary that supports FPM and FCGI mode can be built.
2 Compile PHP 7 with PHP-FPM and Fastcgi
Download and extract PHP 7 from Github:
mkdir -p /opt/php-7.0.32
mkdir /usr/local/src/php7-build
cd /usr/local/src/php7-build
wget http://de2.php.net/get/php-7.0.32.tar.bz2/from/this/mirror -O php-7.0.32.tar.bz2
tar jxf php-7.0.32.tar.bz2
cd php-7.0.32/
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.
root@server1:/usr/local/src/php5-build/php-7.0.32#
)
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.32 --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-pdo-mysql --with-mysqli --with-mysql-sock=/var/run/mysqld/mysqld.sock --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/php7-build/php-7.0.32/php.ini-production /opt/php-7.0.32/lib/php.ini
cp /opt/php-7.0.32/etc/php-fpm.conf.default /opt/php-7.0.32/etc/php-fpm.conf
cp /opt/php-7.0.32/etc/php-fpm.d/www.conf.default /opt/php-7.0.32/etc/php-fpm.d/www.conf
Open /opt/php-7.0.32/etc/php-fpm.conf and adjust the following setting (remove the ; in front of the pid line):
nano /opt/php-7.0.32/etc/php-fpm.conf
[...] pid = run/php-fpm.pid [...]
Then open /opt/php-7.0.32/etc/php-fpm.d/www.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.32/etc/php-fpm.d/www.conf
[...] listen = 127.0.0.1:8999 [...]
3 Create the init script and systemd unit file
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.32-fpm
#! /bin/sh ### BEGIN INIT INFO # Provides: php-7.0.32-fpm # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts php-7.0.32-fpm # Description: starts the PHP FastCGI Process Manager daemon ### END INIT INFO php_fpm_BIN=/opt/php-7.0.32/sbin/php-fpm php_fpm_CONF=/opt/php-7.0.32/etc/php-fpm.conf php_fpm_PID=/opt/php-7.0.32/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.32-fpm
insserv php-7.0.32-fpm
And now create the systemd unit file
nano /lib/systemd/system/php-7.0.32-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.32/var/run/php-fpm.pid
ExecStart=/opt/php-7.0.32/sbin/php-fpm --nodaemonize --fpm-config /opt/php-7.0.32/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
Enable the service and reload systemd:
systemctl enable php-7.0.32-fpm.service
systemctl daemon-reload
Finally start PHP-FPM.
For systems with traditional init system, run:
/etc/init.d/php-7.0.32-fpm start
The result should be:
/etc/init.d/php-7.0.32-fpm start
Starting php-fpm done
On servers that use systemd, use this command instead:
systemctl start php-7.0.32-fpm.service
To enable the Zend OPcache, open /opt/php-7.0.32/lib/php.ini...
nano /opt/php-7.0.32/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.
Test the PHP version:
cd /opt/php-7.0.32/bin
./php --version
The output should be similar to this screenshot.
Please note: The screenshot is from PHP 7.0.0, the tutorial gets updated continuously for new PHP 7 versions but we don't take new screenshots each time, so the PHP 7 version that you will see on your server is probably newer. The current version of this tutorial is for php-7.0.32.
4 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.32/bin/php-cgi
Path to the php.ini directory: /opt/php-7.0.32/lib
Then g to the PHP-FPM Settings tab and fill out the fields as follows:
Path to the PHP-FPM init script: php-7.0.32-fpm
Path to the php.ini directory: /opt/php-7.0.32/lib
Path to the PHP-FPM pool directory: /opt/php-7.0.32/etc/php-fpm.d
5 Links
- PHP: http://www.php.net/
- ISPConfig: http://www.ispconfig.org/
- Debian: http://www.debian.org/