Instalar PHP 5.6 como adicional PHP-FPM & FastCgi para ISPconfig en Ubuntu 16.04 ?

Aunque lo ideal es que trabajemos con php7 aun hay scripts en php5 que por algunas razones debemos instalar, y este un excelente metodo para poder  migrar de php5 a php7, imaginemosnos que podemos swichar de una version a otra en 1 minutos y ver las diferencias.

1.- Configurar dependencias

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

2.- Descargar y extraer PHP 5.6 desde php.net

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

3.- Prepara archivo de configuración.

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

Si miramos al fina la instruccion  –enable-fpm forza a que trabajemos con fpm

make
make install

4.- copiamos php.ini y php-fpm.conf en la correcta ubicación.

cp /usr/local/src/php5-build/php-5.6.30/php.ini-production /opt/php-5.6.30/lib/php.ini
cp /opt/php-5.6.30/etc/php-fpm.conf.default /opt/php-5.6.30/etc/php-fpm.conf

Creamos el archivo pool de php-fpm.d.

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

Abrimos “/opt/php-5.6.30/etc/php-fpm.conf” asi:

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

Buscamos y editamos las siguientes lineas para que nuestro archivo quede asi:

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

5.- Creasmo el archivo init
Esto es para que la anterior configuracion funcione incliso despes de reiniciar el servidor.
Creamos el archivo  “/lib/systemd/system/php-5.6.30-fpm.service” asi:

vim /lib/systemd/system/php-5.6.30-fpm.service

donde colocamos esto:

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

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

[Install]
WantedBy=multi-user.target

Abilitamos el servicio al reiniciar el server.

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

inicializamos PHP-FPM

systemctl start php-5.6.30-fpm.service

Habilitamos opcache editando el archivo “/opt/php-5.6.30/lib/php.ini” asi

vim /opt/php-5.6.30/lib/php.ini

Agregamos esto al final:

[...]
zend_extension=opcache.so

Testeamos la version de php

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

php 5.6 .25 version

6.- Habilitamos PHP5.6 en ISPConfig.
En ISPConfig 3.1, se puede configurar la nueva versión de PHP en “Sistema> Versiones PHP adicionales”. En la pestaña Nombre, solo debe completar un nombre para la versión de PHP (por ejemplo, PHP 5.6.30): esta versión de PHP se mostrará debajo de este nombre en la configuración del sitio web en ISPConfig:
php additional 1

Vaya a la pestaña Configuración de FastCGI y complete los campos de la siguiente manera:
Path to the PHP FastCGI binary: /opt/php-5.6.30/bin/php-cgi
Path to the php.ini directory: /opt/php-5.6.30/lib

php additional 2

A continuación, vaya a la pestaña Configuración de PHP-FPM y complete los campos de la siguiente manera:

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

php additional 3

OPCIONAL INSTALAR XDBUG

cd /tmp/
mkdir xdebug
cd xdebug/
wget https://pecl.php.net/get/xdebug-2.5.5.tgz
tar xf xdebug-2.5.5.tgz
cd xdebug-2.5.5
/opt/php-5.6.30/bin/phpize
./configure --with-php-config=/opt/php-5.6.30/bin/php-config
make
make install

Editar php.ini
vim /opt/php-5.6.30/lib/php.ini
Agregar esta linea
zend_extension=/opt/php-5.6.30/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *