VestaCP-MultiPHP

En este post os vamos a enseñar como tener varias versiones de PHP  y poder gestionarlas desde VestaCP, para ello necesitaremos PHPBrew.

Instalar dependencias

# apt-get install build-essential libssl-dev libxml2-dev pkg-config libssl-dev libsslcommon2-dev libbz2-dev libcurl4-openssl-dev libmysqlclient-dev libgdbm-dev libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev libxml2 libxml2-dev libmcrypt4 libmcrypt-dev libmhash2 libmhash-dev libmm-dev libmm14 libtidy-dev libtidy-0.99-0 libxslt1-dev libxslt1.1 libfreetype6 libfreetype6-dev libicu-dev libreadline-dev

Modificaciones para que funcione PHP 5.3/5.4, omitir este paso en caso de no usar estas versiones de PHP
# mkdir /usr/include/freetype2/freetype
# ln -s /usr/include/freetype2/freetype.h /usr/include/freetype2/freetype/freetype.h

Instalar y configurar PHPBrew

# curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
# chmod +x phpbrew
# sudo mv phpbrew /usr/bin/phpbrew
# mkdir -p /usr/local/php
# phpbrew init --root=/usr/local/php
# export PHPBREW_ROOT=/usr/local/php
# [[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc

Podemos ver que versiones de PHP podemos instalar con estos comandos:
# phpbrew update
# phpbrew update --old

Solo para Ubuntu 16.04 / PHP 5.3

Para Ubuntu 16.04 necesitas una versión antigua de la libreria de OpenSSL. Omitir este paso en caso de no usar Ubuntu 16.04 y PHP 5.3

# cd /usr/src
# wget https://www.openssl.org/source/openssl-0.9.8zb.tar.gz
# tar xfvz openssl-0.9.8zb.tar.gz
# cd openssl-0.9.8zb
# mkdir /usr/local/sslold
# ./config --prefix=/usr/local --openssldir=/usr/local/sslold
# make
# make install
En el siguiente paso deberemos cambiar --with-openssl-dir=/usr/include/openssl por --with-openssl-dir=/usr/local/sslold.

Compilando PHP con sus correspondientes módulos

No estás obligado a compilar todas las versiones de PHP, puedes compilar las que vayas a utilizar.

-Para  PHP 5.3 ejecutar:
# phpbrew install 5.3 +default +openssl=shared -- --with-openssl-dir=/usr/include/openssl --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysql=mysqlnd --with-mysqli=mysqlnd --enable-pdo --with-pdo-mysql=mysqlnd --enable-exif --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-zlib-dir=/usr --with-mcrypt=/usr --with-mhash --with-xsl=/usr --enable-zip --enable-cgi --with-curl --with-gd --enable-pcntl --enable-mbregex --enable-gd-native-ttf --with-libdir=lib64 --enable-dba=shared --enable-intl --with-readline=/usr --enable-simplexml \--enable-soap --enable-zip --with-mhash=yes --enable-shmop --enable-sockets --enable-wddx --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-cdb --with-iconv --enable-exif --enable-ftp --with-gettext --with-pic

-Para  PHP 5.4 ejecutar:
# phpbrew install 5.4 +default +openssl=shared -- --with-openssl-dir=/usr/include/openssl --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysql=mysqlnd --with-mysqli=mysqlnd --enable-pdo --with-pdo-mysql=mysqlnd --enable-exif --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-zlib-dir=/usr --with-mcrypt=/usr --with-mhash --with-xsl=/usr --enable-zip --enable-cgi --with-curl --with-gd --enable-pcntl --enable-mbregex --enable-gd-native-ttf --with-libdir=lib64 --enable-dba=shared --enable-intl --with-readline=/usr --enable-simplexml \--enable-soap --enable-zip --with-mhash=yes --enable-shmop --enable-sockets --enable-wddx --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-cdb --with-iconv --enable-exif --enable-ftp --with-gettext --with-pic

-Para  PHP 5.5 ejecutar:
# phpbrew install 5.5 +default +openssl=shared -- --with-openssl-dir=/usr/include/openssl --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysql=mysqlnd --with-mysqli=mysqlnd --enable-pdo --with-pdo-mysql=mysqlnd --enable-exif --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-zlib-dir=/usr --with-mcrypt=/usr --with-mhash --with-xsl=/usr --enable-zip --enable-cgi --with-curl --with-gd --enable-pcntl --enable-mbregex --enable-gd-native-ttf --with-libdir=lib64 --enable-dba=shared --enable-intl --with-readline=/usr --enable-simplexml \--enable-soap --enable-zip --with-mhash=yes --enable-shmop --enable-sockets --enable-wddx --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-cdb --with-iconv --enable-exif --enable-ftp --with-gettext --with-pic

-Para  PHP 5.6 ejecutar:
# phpbrew install 5.6 +default +openssl=shared -- --with-openssl-dir=/usr/include/openssl --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysql=mysqlnd --with-mysqli=mysqlnd --enable-pdo --with-pdo-mysql=mysqlnd --enable-exif --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-zlib-dir=/usr --with-mcrypt=/usr --with-mhash --with-xsl=/usr --enable-zip --enable-cgi --with-curl --with-gd --enable-pcntl --enable-mbregex --enable-gd-native-ttf --with-libdir=lib64 --enable-dba=shared --enable-intl --with-readline=/usr --enable-simplexml \--enable-soap --enable-zip --with-mhash=yes --enable-shmop --enable-sockets --enable-wddx --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-cdb --with-iconv --enable-exif --enable-ftp --with-gettext --with-pic

-Para  PHP 7.0 ejecutar:
# phpbrew install 7.0 +default +openssl=shared -- --with-openssl-dir=/usr/include/openssl --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysql=mysqlnd --with-mysqli=mysqlnd --enable-pdo --with-pdo-mysql=mysqlnd --enable-exif --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-zlib-dir=/usr --with-mcrypt=/usr --with-mhash --with-xsl=/usr --enable-zip --enable-cgi --with-curl --with-gd --enable-pcntl --enable-mbregex --enable-gd-native-ttf --with-libdir=lib64 --enable-dba=shared --enable-intl --with-readline=/usr --enable-simplexml \--enable-soap --enable-zip --with-mhash=yes --enable-shmop --enable-sockets --enable-wddx --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-cdb --with-iconv --enable-exif --enable-ftp --with-gettext --with-pic

-Para  PHP 7.1 ejecutar:
# phpbrew install 7.1 +default +openssl=shared -- --with-openssl-dir=/usr/include/openssl --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysql=mysqlnd --with-mysqli=mysqlnd --enable-pdo --with-pdo-mysql=mysqlnd --enable-exif --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-zlib-dir=/usr --with-mcrypt=/usr --with-mhash --with-xsl=/usr --enable-zip --enable-cgi --with-curl --with-gd --enable-pcntl --enable-mbregex --enable-gd-native-ttf --with-libdir=lib64 --enable-dba=shared --enable-intl --with-readline=/usr --enable-simplexml \--enable-soap --enable-zip --with-mhash=yes --enable-shmop --enable-sockets --enable-wddx --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-cdb --with-iconv --enable-exif --enable-ftp --with-gettext --with-pic

Crear enlaces simbólicos

Crearemos los enlaces de las versiones de PHP que hayamos compilado, ojo puede que hayan actualizado alguna versión de PHP desde que se ha creado este post y no conicida php-X.X.XX debemos fijarnos en la versión exacta de PHP que nos indica en el paso anterior, cuando empieza a compilar aparece un mensaje tipo: tail -F /root/.phpbrew/build/php-X.X.XX/build.log

-Para  PHP 5.3 ejecutar:
# ln -s /usr/local/php/php/php-5.3.29 /usr/local/php/php53

-Para  PHP 5.4 ejecutar:
# ln -s /usr/local/php/php/php-5.4.45 /usr/local/php/php54

-Para  PHP 5.5 ejecutar:
# ln -s /usr/local/php/php/php-5.5.38 /usr/local/php/php55

-Para  PHP 5.6 ejecutar:
# ln -s /usr/local/php/php/php-5.6.31 /usr/local/php/php56

-Para  PHP 7.0 ejecutar:
# ln -s /usr/local/php/php/php-7.0.14 /usr/local/php/php70

-Para  PHP 7.1 ejecutar:
# ln -s /usr/local/php/php/php-7.1.6 /usr/local/php/php71

Activando módulos de Apache necesarios
# a2enmod actions cgi
# service apache2 restart

Creando Plantillas para VestaCP

Como en el paso anterior solo ejecutaremos los comandos para las versiones de php que hayamos compilado.

-Para  PHP 5.3 ejecutar:
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php53.sh -O /usr/local/vesta/data/templates/web/apache2/php53.sh
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php53.tpl
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php53.stpl

-Para  PHP 5.4 ejecutar:
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php54.sh -O /usr/local/vesta/data/templates/web/apache2/php54.sh
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php54.tpl
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php54.stpl

-Para  PHP 5.5 ejecutar:
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php55.sh -O /usr/local/vesta/data/templates/web/apache2/php55.sh
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php55.tpl
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php55.stpl

-Para  PHP 5.6 ejecutar:
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php56.sh -O /usr/local/vesta/data/templates/web/apache2/php56.sh
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php56.tpl
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php56.stpl

-Para  PHP 7.0 ejecutar:
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php70.sh -O /usr/local/vesta/data/templates/web/apache2/php70.sh
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php70.tpl
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php70.stpl

-Para  PHP 7.1 ejecutar:
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php71.sh -O /usr/local/vesta/data/templates/web/apache2/php71.sh
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php71.tpl
# wget http://git.scit.ch/rs/VestaCP-MultiPHP/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php71.stpl

– Actualizar permisos a las plantillas:
# chmod 755 /usr/local/vesta/data/templates/web/apache2/*

Cuando vayamos a nuestro panel VestaCP ya podremos elegir que versión de PHP queremos:
VestaCP-MultiPHP

Basado en https://git.scit.ch/rs/VestaCP-MultiPHP

To write a comment on this article, fill out the form below. Fields marked with an asterisk (*) are required.