In this article i will show you how to install multiple php version in localhost (php 5.3.29 and php5.5.0).
To install multiple php in your machine, wee need PHPFarm and FastCGI.
Let’s make it!
Pre-requisite
First, install apache and php (if you don’t have).
sudo apt-get install apache2 php5
Update your machine
sudo apt-get update sudo apt-get upgrade
Dependencies
sudo apt-get install build-essential libxml2-dev libcurl4-openssl-dev pkg-config libmysqlclient-dev
Git
sudo apt-get install git
Phpfarm
cd /opt sudo git clone git://git.code.sf.net/p/phpfarm/code phpfarm
After install it, will created a folder “phpfarm” inside /opt/ like this :
Compile PHP
Create 2 file inside phpfarm/src
a) custom-options-5.3.29.sh and copy this script :
#gcov='--enable-gcov' configoptions="\ --enable-bcmath \ --enable-calendar \ --enable-exif \ --enable-ftp \ --enable-mbstring \ --enable-pcntl \ --enable-soap \ --enable-sockets \ --enable-sqlite-utf8 \ --enable-wddx \ --enable-zip \ --disable-debug \ --with-mysql \ --with-zlib \ --with-gettext \ --with-pdo-mysql \ --with-curl \ --with-openssl \ $gcov"
b) custom-options-5.5.0.sh and copy the following script :
#gcov='--enable-gcov' configoptions="\ --enable-bcmath \ --with-mysqli \ --with-curl \ --with-png \ --with-gd \ --enable-gd-native-ttf \ --enable-calendar \ --enable-exif \ --enable-ftp \ --enable-mbstring \ --enable-pcntl \ --enable-soap \ --with-pdo-mysql \ --enable-sockets \ --enable-sqlite-utf8 \ --enable-wddx \ --enable-zip \ --with-openssl \ --with-jpeg-dir=/usr/lib \ --with-zlib \ --with-gettext \ --with-mcrypt \ $gcov"
Now, compile php 5.3.29 and 5.5.0
*This will take a several minutes
cd /opt/phpfarm/src sudo ./compile.sh 5.3.29 sudo ./compile.sh 5.5.0
After installed, you can see two new folder “php-5.3.29” and “php-5.5.0” :
And link executable inside /opt/phpfarm/inst/bin/ :
Install & Enable FastCGI
sudo apt-get install libapache2-mod-fastcgi apache2-mpm-worker apache2-suexec sudo a2enmod actions fastcgi suexec sudo service apache2 restart
Create folder cgi-bin:
cd /var/www/html/ sudo mkdir cgi-bin
Create file “php-5.3.29” inside /var/www/html/cgin-bin/ and copy the following script :
#!/bin/sh PHPRC="/etc/php5/cgi/5.3.29/" export PHPRC PHP_FCGI_CHILDREN=3 export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=5000 export PHP_FCGI_MAX_REQUESTS exec /opt/phpfarm/inst/bin/php-cgi-5.3.29
Create file “php-5.5.0” inside /var/www/html/cgin-bin/ and copy the following script :
#!/bin/sh PHPRC="/etc/php5/cgi/5.5.0/" export PHPRC PHP_FCGI_CHILDREN=3 export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=5000 export PHP_FCGI_MAX_REQUESTS exec /opt/phpfarm/inst/bin/php-cgi-5.5.0
Make the file executable
sudo chmod +x /var/www/html/cgi-bin/php-cgi-5.3.29 sudo chmod +x /var/www/html/cgi-bin/php-cgi-5.5.0
Configure virtualhost
Create file “virtualhost.conf” :
cd /etc/apache2/sites-enabled/ sudo vi virtualhost.conf
Paste this script to virtualhost.conf
<VirtualHost *:80> ServerName php53.localhost DocumentRoot /var/www/html/php53 FastCgiServer /var/www/html/cgi-bin/php-cgi-5.3.29 ScriptAlias /cgi-bin-php/ /var/www/html/cgi-bin/ <Directory "/var/www/html/php53/"> AddHandler php-cgi .php Action php-cgi /cgi-bin-php/php-cgi-5.3.29 <FilesMatch "\.php$"> SetHandler php-cgi </FilesMatch> </Directory> </VirtualHost> <VirtualHost *:80> ServerName php55.localhost DocumentRoot /var/www/html/php55 FastCgiServer /var/www/html/cgi-bin/php-cgi-5.5.0 ScriptAlias /cgi-bin-php/ /var/www/html/cgi-bin/ <Directory "/var/www/html/php55/"> AddHandler php-cgi .php Action php-cgi /cgi-bin-php/php-cgi-5.5.0 <FilesMatch "\.php$"> SetHandler php-cgi </FilesMatch> </Directory> </VirtualHost>
Create two folder “php53” & “php55” :
Create a file index.php, copy script below and put to folder “php53” & “php55” :
<?php phpinfo(); ?>
Add Subdomain
Edit file :
sudo vi /etc/hosts/
Add the line :
127.0.0.1 localhost php53.localhost php55.localhost
RESULT
reference : https://gist.github.com/gmodarelli/5887778