Debian 9 ships with PHP 7.0 as default PHP version. Major PHP versions are not 100% compatible with each other, so a website might require a newer or older PHP version to work. ISPConfig supports it to use multiple PHP versions on the same server, the PHP version can be selected for each website individually in the website settings. This tutorial shows how to install PHP 7.1, 7.2, and 5.6 as FPM and FCGI mode alongside PHP 7.0 on a Debian 9 server. The additional PHP versions are installed in the /opt folder, so their installation does not affect the default PHP version

 

1 Preliminary Note

I will install PHP 7.1, 7.2 and 5.6. Please note that PHP-FPM can be used on both Apache and Nginx servers while FastCGI is available only for Apache servers.

 

2 Install the prerequisites

Install the prerequisites for building PHP 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-dev libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng-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

 

cd /usr/include
ln -s x86_64-linux-gnu/curl

 

(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.1.14#)

 

3 Compile PHP 7.1 as PHP-FPM and Fastcgi

 

Download and extract PHP archive:

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

 

cd php-7.1.14/

 

Configure and build PHP 7.1 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.1 --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.1-build/php-7.1/php.ini-production /opt/php-7.1/lib/php.ini

 

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

 

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

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

 

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

 

Then open /opt/php-7.1/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.1/etc/php-fpm.d/www.conf

 

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

 

3.1 Create the systemd unit file

 

Next, we'll create the system unit file which is used to start and stop the PHP-FPM daemon.

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

 

with the following content:

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

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

[Install]
WantedBy=multi-user.target

 

Enable the service and reload systemd:

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

 

Finally, start PHP-FPM.

systemctl start php-7.1-fpm.service

 

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

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

 

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

[...]
zend_extension=opcache.so

 

3.2 Enable Memcache (optional)

 

In this chapter, I will compile and enable the PHP Memcached extension.

 

The first step is to install the libmemcached-dev package from Debian.

apt-get install libmemcached-dev

 

Then create a diretory, download the PHP memcache extension from Github, unpack the archive and enter the directory that contains the unpacked files.

mkdir /usr/local/src/php7.1-build/php-memcache
cd /usr/local/src/php7.1-build/php-memcache
wget https://github.com/php-memcached-dev/php-memcached/archive/php7.zip
unzip php7.zip
cd php-memcached-php7

 

Prepare he sources by running the phpize command from PHP 7.1.

/opt/php-7.1/bin/phpize

 

Configure and build the PHP memcache extension.

./configure --with-php-config=/opt/php-7.1/bin/php-config
make
make install

 

To enable the Memcache extension, open /opt/php-7.1/lib/php.ini...

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

 

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

[...]
extension=memcached.so

 

3.3 Install xDebug extension (optional)

 

The xDebug module is a debugging extension for PHP. The installation is optional.

 

Install xDebug with these commands.

cd /opt/php-7.1/etc
../bin/pecl -C ./pear.conf update-channels
../bin/pecl -C ./pear.conf install xdebug

 

Then edit the php.ini file with an editor:

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

 

and add the following line at the end of the file:

zend_extension=/opt/php-7.1/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so

 

Finally, restart the php-fpm daemon:

systemctl start php-7.1-fpm.service

 

Test the PHP version:

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

 

The output should be similar to this screenshot.

 

Please note: The screenshot is from PHP 7.1.14, the tutorial gets updated continuously for new PHP versions but we don't take new screenshots each time, so the PHP version that you will see on your server might be newer. The current version of this tutorial is for php-7.1.14.

 

3.4 Enable PHP 7.1 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 7.1) - 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.1/bin/php-cgi
Path to the php.ini directory: /opt/php-7.1/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.1-fpm
Path to the php.ini directory: /opt/php-7.1/lib
Path to the PHP-FPM pool directory: /opt/php-7.1/etc/php-fpm.d

 

4 Compile PHP 7.2 as PHP-FPM and Fastcgi

 

Download and extract PHP from php.net and unpack the tar.bz2 file:

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

 

 cd php-7.2.2/

 

Configure and build PHP 7.2 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.2 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --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 --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.2-build/php-7.2.2/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

 

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

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

 

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

 

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

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

 

[...]
listen = 127.0.0.1:8998
[...]

 

4.1 Create the systemd unit file

 

Next, we'll create the system unit file which is used to start and stop the PHP-FPM daemon.

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

 

with the following content:

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

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

[Install]
WantedBy=multi-user.target

 

Enable the service and reload systemd:

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

 

Finally, start PHP-FPM.

systemctl start php-7.2-fpm.service

 

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

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

 

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

[...]
zend_extension=opcache.so

 

4.2 Enable Memcache (optional)

 

In this chapter, I will compile and enable the PHP Memcached extension.

 

The first step is to install the libmemcached-dev package from Debian.

apt-get install libmemcached-dev

 

Then create a diretory, download the PHP memcache extension from Github, unpack the archive and enter the directory that contains the unpacked files.

mkdir /usr/local/src/php7.2-build/php-memcache
cd /usr/local/src/php7.2-build/php-memcache
wget https://github.com/php-memcached-dev/php-memcached/archive/php7.zip
unzip php7.zip
cd php-memcached-php7

 

Prepare he sources by running the phpize command from PHP 7.2.

/opt/php-7.2/bin/phpize

 

Configure and build the PHP memcache extension.

./configure --with-php-config=/opt/php-7.2/bin/php-config
make
make install

 

To enable the Memcache extension, open /opt/php-7.2/lib/php.ini...

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

 

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

[...]
extension=memcached.so

 

4.3 Install xDebug extension (optional)

 

The xDebug module is a debugging extension for PHP. The installation is optional.

 

Install xDebug with these commands.

cd /opt/php-7.2/etc
pecl -C ./pear.conf update-channels
pecl -C ./pear.conf install xdebug

 

Then edit the php.ini file with an editor:

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

 

and add the following line at the end of the file:

zend_extension=/opt/php-7.2/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so

 

Finally, restart the php-fpm daemon:

systemctl start php-7.2-fpm.service

 

Test the PHP version:

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

 

 

Please note: The screenshot is from PHP 7.2.2, the tutorial gets updated continuously for new PHP versions but we don't take new screenshots each time, so the PHP version that you will see on your server might be newer. The current version of this tutorial is for php-7.2.2.

 

4.4 Enable PHP 7.2 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 7.2) - 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.2/bin/php-cgi
Path to the php.ini directory: /opt/php-7.2/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.2-fpm
Path to the php.ini directory: /opt/php-7.2/lib
Path to the PHP-FPM pool directory: /opt/php-7.2/etc/php-fpm.d

 

5 Compile PHP 5.6 as PHP-FPM and Fastcgi

 

Download PHP and unpack the tar.bz2 archive:

mkdir -p /opt/php-5.6
mkdir /usr/local/src/php5.6-build
cd /usr/local/src/php5.6-build
wget http://de2.php.net/get/php-5.6.33.tar.bz2/from/this/mirror -O php-5.6.33.tar.bz2
tar jxf php-5.6.33.tar.bz2

 

The OpenSSL version in Debian 9 is too new for PHP 5.6, so we'll have to compile an older version in /opt/openssl to use it with PHP 5.6.

cd /tmp
wget "https://www.openssl.org/source/old/1.0.1/openssl-1.0.1t.tar.gz"
tar xzf openssl-1.0.1t.tar.gz 
cd openssl-1.0.1t
./config shared --prefix=/opt/openssl
make -j $(nproc) && make install
ln -s /opt/openssl/lib /opt/openssl/lib/x86_64-linux-gnu
wget -O /opt/openssl/ssl/cert.pem "http://curl.haxx.se/ca/cacert.pem"

 

Create a symlink so PHP will find the freetype, libcrypto and libssl libraries.

mkdir /usr/include/freetype2/freetype
ln -s /usr/include/freetype2/freetype.h /usr/include/freetype2/freetype/freetype.h
ln -s /opt/openssl/lib/libcrypto.so.1.0.0 /usr/lib/x86_64-linux-gnu/
ln -s /opt/openssl/lib/libssl.so.1.0.0 /usr/lib/x86_64-linux-gnu/
ln -fs /opt/openssl /usr/local/ssl

 

Enter the folder which contains the unpacked PHP source files.

cd /usr/local/src/php5.6-build/php-5.6.33/

 

Configure and build PHP 5.6 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 --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-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=/opt/openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --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.6-build/php-5.6.33/php.ini-production /opt/php-5.6/lib/php.ini

 

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

 

mkdir -p /opt/php-5.6/etc/php-fpm.d

 

Open /opt/php-5.6/etc/php-fpm.conf and adjust the following setting:

 

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

 

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

 

5.1 Create the systemd unit file

 

Next, we'll create the system unit file which is used to start and stop the PHP-FPM daemon.

 

nano /lib/systemd/system/php-5.6-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/var/run/php-fpm.pid
ExecStart=/opt/php-5.6/sbin/php-fpm --nodaemonize --fpm-config /opt/php-5.6/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-fpm.service
systemctl daemon-reload

 

Finally, start PHP-FPM.

systemctl start php-5.6-fpm.service

 

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

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

 

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

[...]
zend_extension=opcache.so

 

5.2 Enable Memcache (optional)

 

In this chapter, I will compile and enable the PHP Memcached extension.

 

The first step is to install the libmemcached-dev package from Debian.

apt-get install libmemcached-dev

 

Then run these commands to build the memcache extension

cd /opt/php-5.6/etc
pecl -C ./pear.conf update-channels
pecl -C ./pear.conf install memcache

 

To enable the Memcache extension, open /opt/php-5.6/lib/php.ini...

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

 

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

[...]
extension=memcache.so

 

Finally, restart the php-fpm daemon:

systemctl start php-5.6-fpm.service

 

Test the PHP version:

cd /opt/php-5.6/bin
/php --version

 

Please note: The screenshot is from PHP 5.6.33, the tutorial gets updated continuously for new PHP versions but we don't take new screenshots each time, so the PHP version that you will see on your server might be newer. The current version of this tutorial is for php-5.6.33.

 

5.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) - 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-5.6/bin/php-cgi
Path to the php.ini directory: /opt/php-5.6/lib

 

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-fpm
Path to the php.ini directory: /opt/php-5.6/lib
Path to the PHP-FPM pool directory: /opt/php-5.6/etc/php-fpm.d

 

Hai trovato utile questa risposta? 0 Utenti hanno trovato utile questa risposta (0 Voti)