In this post, we will show you how to have several PHP versions and manage them from VestaCP. To do this, we will need PHPBrew. PHPBrew lets you compile different PHP versions, which you can even save in your HOME folder. This tutorial is for VestaCP with Ubuntu 16.
UPDATES
UPDATE [09/01/2018]: Apparently, PHPBrew made significant changes that partially break the tutorial, so we have had to update it by making significant changes to the tutorial.
UPDATE [09/21/2020]: This tutorial may be somewhat outdated, so if you need several PHP versions, we recommend installing HestiaCP.
Install dependencies
First, install all the dependencies needed for PHPBrew to work correctly:
# 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 lcov libzip-devCreate the following links:
# cd /usr/local/include
# ln -s /usr/include/x86_64-linux-gnu/curl curl
# cd /usr/include
# ln -s x86_64-linux-gnu/curl
# apt-get install libcurl4-gnutls-dev libzip-devInstall and configure PHPBrew
To install PHPBrew on both versions of Ubuntu, proceed as follows:
# curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
# chmod +x phpbrew
# mv phpbrew /usr/bin/phpbrew
# mkdir -p /usr/local/phpThen edit ~/.bashrc and add the following at the very end:
# nano ~/.bashrcphpbrew init --root=/usr/local/php
export PHPBREW_ROOT=/usr/local/php
[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrcYou can see which PHP versions you can install with these commands:
# phpbrew update
# phpbrew update --oldCompile different PHP versions
You do not have to compile all PHP versions; you can compile the ones you will use.
-For PHP 5.3 run:
# phpbrew install 5.3 +default +iconv +exif +ftp +mysql +gd +intl +zlib +cgi +dba +wddx-For PHP 5.4 run:
# phpbrew install 5.4 +default +iconv +exif +ftp +mysql +gd +intl +zlib +cgi +dba +wddx-For PHP 5.5 run:
# phpbrew install 5.5 +default +iconv +exif +ftp +mysql +gd +intl +zlib +cgi +dba +wddx-For PHP 5.6 run:
# phpbrew install 5.6 +default +iconv +exif +ftp +mysql +gd +intl +zlib +cgi +dba +wddx-For PHP 7.0 run:
# phpbrew install 7.0 +default +iconv +exif +ftp +mysql +gd +intl +zlib +cgi +dba +wddx-For PHP 7.1 run:
# phpbrew install 7.1 +default +iconv +exif +ftp +mysql +gd +intl +zlib +cgi +dba +wddx-For PHP 7.2 run:
# phpbrew install 7.2 +default +iconv +exif +ftp +mysql +gd +intl +zlib +cgi +dba +wddx-For PHP 7.3 run:
# phpbrew install 7.3 +default +iconv +exif +ftp +mysql +gd +intl +zlib +cgi +dba +wddxInstall additional extensions
For PHP versions higher than 7.x, the OpenSSL extension, for example, is not installed by default. That is why we will have to install it manually (as well as any other extension we need). To install an extension with PHPBrew, follow these steps:
Display the versions you have:
# phpbrew listSelect the PHP version for which you want to install the extension:
# phpbrew use php-5.6.xxNow install the required extension. In this case, as an example, we will install OpenSSL:
# phpbrew ext install opensslCreate symbolic links
We will create links for the PHP versions we have compiled so that we can run the different PHP versions from the VestaCP templates:
# ln -s /usr/local/php/php/php-X.X.XX /usr/local/php/phpXXWARNING: If the PHP version is updated, the last two numbers of the version in the link may change, which is why these links must be created manually. Even so, here are the links that needed to be created when this post was written.
-For PHP 5.3 run:
# ln -s /usr/local/php/php/php-5.3.29 /usr/local/php/php53-For PHP 5.4 run:
# ln -s /usr/local/php/php/php-5.4.45 /usr/local/php/php54-For PHP 5.5 run:
# ln -s /usr/local/php/php/php-5.5.38 /usr/local/php/php55-For PHP 5.6 run:
# ln -s /usr/local/php/php/php-5.6.31 /usr/local/php/php56-For PHP 7.0 run:
# ln -s /usr/local/php/php/php-7.0.14 /usr/local/php/php70-For PHP 7.1 run:
# ln -s /usr/local/php/php/php-7.1.6 /usr/local/php/php71-For PHP 7.2 run:
# ln -s /usr/local/php/php/php-7.2.10 /usr/local/php/php72-For PHP 7.3 run:
# ln -s /usr/local/php/php/php-7.3.33 /usr/local/php/php73Finally, enable the required Apache modules:
# a2enmod actions cgi
# service apache2 restartCreating templates for VestaCP
As in the previous step, we will only run the commands for the PHP versions we have compiled. If you have installed all versions, you can run the following code, which runs a bash script that creates all the templates automatically. Otherwise, run the lines for the versions you have installed:
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/instalar_plantillas.shGrant it permissions and run it:
# chmod u+x instalar_plantillas.sh
# ./instalar_plantillas.shIf you have installed a specific PHP version, run the commands for that version:
-For PHP 5.3 run:
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php53.sh -O /usr/local/vesta/data/templates/web/apache2/php53.sh
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php53.tpl
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php53.stpl-For PHP 5.4 run:
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php54.sh -O /usr/local/vesta/data/templates/web/apache2/php54.sh
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php54.tpl
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php54.stpl-For PHP 5.5 run:
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php55.sh -O /usr/local/vesta/data/templates/web/apache2/php55.sh
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php55.tpl
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php55.stpl-For PHP 5.6 run:
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php56.sh -O /usr/local/vesta/data/templates/web/apache2/php56.sh
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php56.tpl
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php56.stpl-For PHP 7.0 run:
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php70.sh -O /usr/local/vesta/data/templates/web/apache2/php70.sh
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php70.tpl
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php70.stpl-For PHP 7.1 run:
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php71.sh -O /usr/local/vesta/data/templates/web/apache2/php71.sh
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php71.tpl
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php71.stpl-For PHP 7.2 run:
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php72.sh -O /usr/local/vesta/data/templates/web/apache2/php72.sh
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php72.tpl
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php72.stpl-For PHP 7.3 run:
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php73.sh -O /usr/local/vesta/data/templates/web/apache2/php73.sh
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.tpl -O /usr/local/vesta/data/templates/web/apache2/php73.tpl
# wget https://gitlab.com/clouding.io-tech.support/vestacp-multiphp/raw/master/php.stpl -O /usr/local/vesta/data/templates/web/apache2/php73.stplNow we need to update the permissions for the templates:
# chmod 755 /usr/local/vesta/data/templates/web/apache2/*When we go to our VestaCP panel, we will now be able to choose which PHP version we want:
Based on https://git.scit.ch/rs/VestaCP-MultiPHP