How to install PHP 7.2 on Ubuntu 14.04 (ISPConfig 3.1)

Ubuntu 14.04 is shipped with PHP 5.5.9 as default PHP version. Since most of CMS now want a most recent version of PHP we gonna explain how-to install a most recent version of PHP.

I’ll explain how to compile and then use PHP 7.2.6 on Ubuntu 14.04 LTS with ISPConfig.

We will see also how-to configure ISPConfig for using the new PHP engine.

Let’s start by creating the necessary folders, downloading the latest PHP 7.0 version from php.net website and extract it:

mkdir -p /opt/php-7.2
mkdir /usr/local/src/php7-build
cd /usr/local/src/php7-build
wget http://de2.php.net/get/php-7.2.6.tar.bz2/from/this/mirror -O php-7.2.6.tar.bz2
tar jxf php-7.2.6.tar.bz2

cd php-7.2.6

Before starting we need to Install the necessary libraries and building tools for compile our PHP version.
If you are not logged-in as root, run the commands with sudo in front of each commands:

apt-get install build-essential nano

apt-get install libfcgi-dev libfcgi0ldbl libjpeg-turbo8-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

After the installation of the required build-tools, we can now go ahead and start configuring & enabling the PHP modules that we want to use, before compiling PHP:

./configure --prefix=/opt/php-7.2 --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

Now we can start compiling PHP and install the new compiled module, our new version of PHP will be installed under /opt/php-7.0/ in order to do not interfere with other system stuff, on SSH now type:

make
make install

The compile will take a while (it vary from the server hardware). Once the compile end without errors we can proceed with the next steps

Copy php.ini, php-fpm.conf and www.conf configuration files under /opt/php-7.2/

cp /usr/local/src/php7-build/php-7.2.6/php.ini-production /opt/php-7.2/lib/php.ini
cp /opt/php-7.2/etc/php-fpm.conf.default /opt/php-7.2/etc/php-fpm.conf
cp /opt/php-7.2/etc/php-fpm.d/www.conf.default /opt/php-7.2/etc/php-fpm.d/www.conf

After copying the files we now proceed by adjust the php-fpm.conf file.

I have used the editor vim but you can use you preferred editor like for ex. nano

vim /opt/php-7.2/etc/php-fpm.conf

Inside the configuration file comment out the pid section, I have changed the pid filename in order to have the possibility of compile and use multiple PHP version at the same time, if you leave it as default and then compile other version of PHP and use the same pid filename, you will incure in some issues. After edit the file, save it and proceed with the next step.

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

We need now to change also www.conf file in order to have php-fpm listening on different port (on the default port 9000 and on port 8999 I have already another php-fpm version running). I have chosen the port 8998

vim /opt/php-7.2/etc/php-fpm.d/www.conf
[...]
listen = 127.0.0.1:8999
[...]

We are almost done now, there are only few steps to be done, first of all the init.d file, otherwise our php-fpm will never start automatically. Let’s create now the init.d file:

vim /etc/init.d/php-7.2-fpm
#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-7.2-fpm
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-7.2-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO
php_fpm_BIN=/opt/php-7.2/sbin/php-fpm
php_fpm_CONF=/opt/php-7.2/etc/php-fpm.conf
php_fpm_PID=/opt/php-7.2/var/run/php-7.2-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

Change the permission and set the default run levels

chmod 755 /etc/init.d/php-7.2-fpm
update-rc.d php-7.2-fpm defaults

I strongly suggest to enable the Zend OPcache. In order to do it, edit the php.ini file which is located under /opt/php-7.0/lib/php.ini

vim /opt/php-7.2/lib/php.ini
zend_extension=opcache.so

Let’s tell now to ISPConfig where to find the new PHP engine.

Log-In in ISPConfig 3 panel and configure the new PHP version under System > Additional PHP Versions > Add new PHP version.

On the Name tab, you just fill in a name for the PHP version (e.g. PHP 7.2.6) . This is name is then displayed on the website settings in ISPConfig:

how to install php 7

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

PHP FastCGI binary: /opt/php-7.2/bin/php-cgi
php.ini directory: /opt/php-7.2/lib

how to install php 7

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

PHP-FPM init script: /etc/init.d/php-7.2-fpm
php.ini directory: /opt/php-7.2/lib
PHP-FPM pool directory: /opt/php-7.2/etc/php-fpm.d

how to install php 7

Enjoy your new PHP!

How to install PHP 7.0 on Ubuntu 14.04 (ISPConfig 3.1)

Ubuntu 14.04 is shipped with PHP 5.5.9 as default PHP version. Since most of CMS now want a most recent version of PHP we gonna explain how-to install a most recent version of PHP.

I’ll explain how to compile and then use PHP 7.0.30 on Ubuntu 14.04 LTS with ISPConfig.

We will see also how-to configure ISPConfig for using the new PHP engine.

Let’s start by creating the necessary folders, downloading the latest PHP 7.0 version from php.net website and extract it:

mkdir -p /opt/php-7.0
mkdir /usr/local/src/php7-build
cd /usr/local/src/php7-build
wget http://de2.php.net/get/php-7.0.30.tar.bz2/from/this/mirror -O php-7.0.30.tar.bz2
tar jxf php-7.0.30.tar.bz2

cd php-7.0.30

Before starting we need to Install the necessary libraries and building tools for compile our PHP version.
If you are not logged-in as root, run the commands with sudo in front of each commands:

apt-get install build-essential nano

apt-get install libfcgi-dev libfcgi0ldbl libjpeg-turbo8-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

After the installation of the required build-tools, we can now go ahead and start configuring & enabling the PHP modules that we want to use, before compiling PHP:

./configure --prefix=/opt/php-7.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-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

Now we can start compiling PHP and install the new compiled module, our new version of PHP will be installed under /opt/php-7.0/ in order to do not interfere with other system stuff, on SSH now type:

make
make install

The compile will take a while (it vary from the server hardware). Once the compile end without errors we can proceed with the next steps

Copy php.ini, php-fpm.conf and www.conf configuration files under /opt/php-7.0/

cp /usr/local/src/php7-build/php-7.0.25/php.ini-production /opt/php-7.0/lib/php.ini
cp /opt/php-7.0/etc/php-fpm.conf.default /opt/php-7.0/etc/php-fpm.conf
cp /opt/php-7.0/etc/php-fpm.d/www.conf.default /opt/php-7.0/etc/php-fpm.d/www.conf

After copying the files we now proceed by adjust the php-fpm.conf file.

I have used the editor vim but you can use you preferred editor like for ex. nano

vim /opt/php-7.0/etc/php-fpm.conf

Inside the configuration file comment out the pid section, I have changed the pid filename in order to have the possibility of compile and use multiple PHP version at the same time, if you leave it as default and then compile other version of PHP and use the same pid filename, you will incure in some issues. After edit the file, save it and proceed with the next step.

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

We need now to change also www.conf file in order to have php-fpm listening on different port (on the default port 9000 and on port 8999 I have already another php-fpm version running). I have chosen the port 8998

vim /opt/php-7.0/etc/php-fpm.d/www.conf
[...]
listen = 127.0.0.1:8998
[...]

We are almost done now, there are only few steps to be done, first of all the init.d file, otherwise our php-fpm will never start automatically. Let’s create now the init.d file:

vim /etc/init.d/php-7.0-fpm
#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-7.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-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO
php_fpm_BIN=/opt/php-7.0/sbin/php-fpm
php_fpm_CONF=/opt/php-7.0/etc/php-fpm.conf
php_fpm_PID=/opt/php-7.0/var/run/php-7.0-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

Change the permission and set the default run levels

chmod 755 /etc/init.d/php-7.0-fpm
update-rc.d php-7.0-fpm defaults

I strongly suggest to enable the Zend OPcache. In order to do it, edit the php.ini file which is located under /opt/php-7.0/lib/php.ini

vim /opt/php-7.0/lib/php.ini
zend_extension=opcache.so

Let’s tell now to ISPConfig where to find the new PHP engine.

Log-In in ISPConfig 3 panel and configure the new PHP version under System > Additional PHP Versions > Add new PHP version.

On the Name tab, you just fill in a name for the PHP version (e.g. PHP 7.0.30) . This is name is then displayed on the website settings in ISPConfig:

how to install php 7

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

PHP FastCGI binary: /opt/php-7.0/bin/php-cgi
php.ini directory: /opt/php-7.0/lib

how to install php 7

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

PHP-FPM init script: /etc/init.d/php-7.0-fpm
php.ini directory: /opt/php-7.0/lib
PHP-FPM pool directory: /opt/php-7.0/etc/php-fpm.d

how to install php 7

Enjoy your new PHP!