Install multiple PHP versions in Ubuntu server

Install multiple PHP versions in Ubuntu server

Install Multiple Versions of PHP in Ubuntu LAMP Server

Following steps need to follow in order to install multiple PHP versions in Ubuntu server.

1. Install LAMP Server

If you have not already installed your LAMP server, you should do so now.

$ sudo apt-get update && sudo apt-get upgrade $$ sudo apt-get install apache2

2. Dependencies

Install a few dependencies needed for this setup.

$ sudo apt-get install build-essential git apache2-mpm-worker libapache2-mod-fastcgi php5-fpm

3. PHP Dependencies

Install dependencies needed to compile php5.

$ sudo apt-get build-dep php5

4. Download PHPFarm

Using git to download PHPFarm source.

$ sudo git clone https://github.com/cweiske/phpfarm.git /opt/phpfarm

5. Navigate Directory

Move into the new directory.

$ cd /opt/phpfarm/src

6. Compile PHP

Using PHPFarm to compile any version of php you like, PHP versions list at : http://museum.php.net
NOTE!! Install location is /opt/phpfarm/inst/bin when finished.

$ sudo ./compile.sh 5.4.0
$ sudo ./compile.sh 5.5.0
$ sudo ./compile.sh 5.5.6

7. Enable Fastcgi in Apache

Making sure all the mods are enabled on the server.

$ sudo a2enmod actions fastcgi alias

8. Restart Apache

Restarting Apache to make sure all mods are loaded.

$ sudo service apache2 restart

9. Create FastCgiServer Config

Create the confiuration file for the FastCgi Server.

$ sudo nano /etc/apache2/conf.d/php-cgisetup.conf

10 Edit FastCgiServer Config

You will need to have one line for each version of PHP that you created with PHPFarm, Use (CTRL+O) to save and (CTRL+X) to close.

#php-cgi setup
#used for multiple php versions
FastCgiServer /var/www/cgi-bin/php-cgi-5.4.0
FastCgiServer /var/www/cgi-bin/php-cgi-5.5.0
FastCgiServer /var/www/cgi-bin/php-cgi-5.5.6
ScriptAlias /cgi-bin-php/ /var/www/cgi-bin/

11. Create cgi-bin

Now create the cgi-bin

$ sudo mkdir /var/www/cgi-bin

12. Create php-cgi-5.4.0 File

Create a bin file for PHP-5.4.0.

$ sudo nano /var/www/cgi-bin/php-cgi-5.4.0

13. Edit php-cgi-5.4.0 File

Past this into nano, Use (CTRL+O) to save and (CTRL+X) to close.

#!/bin/sh 
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.4.0

14. Create php-cgi-5.5.0 File

Create a bin file for PHP-5.5.0.

$ sudo nano /var/www/cgi-bin/php-cgi-5.5.0

15. Edit php-cgi-5.5.0 File

Past this into nano, Use (CTRL+O) to save and (CTRL+X) to close.

#!/bin/sh 
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

16. Create php-cgi-5.5.6 File

Create a bin file for PHP-5.5.6.

$ sudo nano /var/www/cgi-bin/php-cgi-5.5.6

17. Edit php-cgi-5.5.6 File

Past this into nano, Use (CTRL+O) to save and (CTRL+X) to close.

#!/bin/sh 
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.6

18. Set cgi-bin Owner

Set owner of the cgi-bin to www-data to allow Apache access to the files.

$ sudo chown -R www-data:www-data /var/www/cgi-bin

19. Set cgi-bin Permissions

Set the permissions to allow the owner access to the cgi-bin folder,

$ sudo chmod -R 0744 /var/www/cgi-bin

20 Navigate Directory

Now to setup a server so move into the apache directory to create a new virtual host.

$ cd /etc/apache2/sites-available

21 Create Virtual Host

Now create a new file called php-dev with nano.

$ sudo nano php-dev

22. Edit Virtual Host

Copy and Past this into nano. Modify the server names if you like but remember them for later on.
notice that all three virtual hosts have the same Document Root and different php versions, Use (CTRL+O) to save and (CTRL+X) to close.

<VirtualHost *:80>
ServerName testphp540.com 
DocumentRoot /var/www 
 <Directory />
   Options FollowSymLinks
   AllowOverride All
   AddHandler php-cgi .php
   Action php-cgi /cgi-bin-php/php-cgi-5.4.0
 </Directory>
 ErrorLog /var/log/apache2/error.log
 LogLevel warn
 CustomLog /var/log/apache2/access.log combined
 </VirtualHost>

 <VirtualHost *:80>
 ServerName testphp550.com
 DocumentRoot /var/www
 <Directory />virtual host
   Options FollowSymLinks
   AllowOverride All
   AddHandler php-cgi .php
   Action php-cgi /cgi-bin-php/php-cgi-5.5.0
 </Directory>
 ErrorLog /var/log/apache2/error.log
 LogLevel warn
 CustomLog /var/log/apache2/access.log combined
 </VirtualHost> 

<VirtualHost *:80>
 ServerName testphp556.com
 DocumentRoot /var/www
 <Directory />
   Options FollowSymLinks
   AllowOverride All
   AddHandler php-cgi .php
   Action php-cgi /cgi-bin-php/php-cgi-5.5.6
 </Directory>
 ErrorLog /var/log/apache2/error.log
 LogLevel warn
 CustomLog /var/log/apache2/access.log combined
 </VirtualHost> 

23. Disable Default Site

Now to get rid of the default site simply disable it.

$ sudo a2dissite default

24. Enable New Site

Now enable the new website.

$ sudo a2ensite php-dev

25. Navigate Directory

Now we need to create a test page for our site.

$ cd /var/www

26. Reload Apache

Reload the apache server to allow for the changes to take place.

$ sudo service apache2 reload

27. Remove Old index.html

You need to delete the old index.

$ rm index.html

28. Create Test Page

$ sudo nano index.php

29. Edit Test Page

Copy this into nano, Use (CTRL+O) to save and (CTRL+X) to close.

<?php
phpinfo();
?>

30 Get Sever IP Address

You need to know the IP address of the server. Usually eth0 so make note of the inet addr:IP

$ ifconfig

31. Open /etc/hosts

Edit the hosts file on your SERVER or OTHER computers that my access these sites threw your network, using the ipaddress from step #39.

$ sudo nano /etc/hosts

32. Edit /etc/hosts

So it should look something like this depending on what your server IP address actually is, Use (CTRL+O) to save and (CTRL+X) to close.

192.168.1.70 testphp540.com
192.168.1.70 testphp550.com
192.168.1.70 testphp556.com

Leave a Reply

error: Content is protected !!