http://www.jabommi.de/wiki/downgrade-php-5-5-to-5-3-ubuntu-14-with-multiple-php-versions/
In this tutorial we will parallel install PHP as FastCGI and as mod_php (default) on Ubuntu 14 using phpfarm . We will first download and compile PHP 3.5.29 (or any other version you like) and then configure a virtual host with FastCGI.
Note: We assume you did have installed LAMP with PHP 5.5x, MySQL and Apache 2 using mod_php. If not please first install it.There are many tutorials on how to install LAMP on Ubuntu 14!
1. Updating system
sudo apt-get update
sudo apt-get ugrade
sudo apt-get install build-essential
Note: You can leave out “sudo apt-get upgrade”, if you dont want to upgrade your system.
Install some libs needed for PHP compilation:sudo apt-get install libxml2 libxml2-dev libssl-dev
sudo apt-get install libcurl4-openssl-dev pkg-config
sudo apt-get install libcurl4-gnutls-dev libjpeg-dev libpng12-dev libmysqlclient -dev
2. Download phpfarm via git
sudo apt-get install git
cd / opt
sudo git clone https://github.com/cweiske/phpfarm
Note: If “git clone” does not work, download phpfarm here and manually extract it to the right location.
3. Configure PHP 3.5.29 compile options
PHP compile options are setted in “options.sh” but can be overwritten by a custom options file. We will create a new file in this case custom.Cd / opt / phpfarm / src
sudo nano custom-options-5.3.29.sh
Type in or copy this:
1
2
3
4
5
6
7
8th
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#gcov = '- enable-gcov' configoptions = "\ - Enable -bcmath \ - Enable -Calendar \ - Enable -exif \ - Enable - ftp \ - Enable -mbstring \ - Enable -pcntl \ - Enable SOAP \ - Enable socket types \ - Enable -sqlite-utf8 \ - Enable -wddx \ - Enable -zip \ --disable-debug \ --with-mysql \ --with-zlib \ --with-gettext \ --with-pdo-mysql \ --with-curl \ --with-openssl \ $ Gcov " |
4. Compile PHP and verify it
cd / opt / phpfarm / src
sudo ./compile.sh 03/05/29
Verify installation:cd / opt / phpfarm / inst / bin
./php-5.3.29 --version
5. Install FastCGI
sudo apt-get install libapache2-mod-fastcgi apache2-mpm-worker apache2-suexec
sudo a2enmod actions fastcgi suexec
sudo service apache2 restart
sudo mkdir / var / www / cgi-bin
cd / var / www / cgi-bin
sudo nano php-cgi-03/05/29
Put the Following code into “php-cgi-3.5.29”:
1
2
3
4
5
6
7
8th
|
#! / 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 |
Make this file executable and chown rights to apache user ( “www-data” by default):sudo chmod + x /var/www/cgi-bin/php-cgi-5.3.29
sudo chown -R www-data: www- data / var / www / cgi-bin
6. Create and configure virtual host
Create a new virtual host “cgidemo”cd / etc / apache2 / sites-available
sudo nano cgidemo.conf
Put this into “cgidemo.conf”:
1
2
3
4
5
6
7
8th
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
<VirtualHost *: 80> Server Name mysite.dev DocumentRoot / var / www / mysite ErrorLog / var / log / apache2 / error_log LogLevel debug CustomLog / var / log / apache2 / access_log combined <Directory "/ var / www / mysite" > Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted < / Directory > < / VirtualHost > <VirtualHost *: 80> ServerAdmin webmaster @ localhost Server Name cgidemo.dev DocumentRoot / var / www / cgidemo # Php-cgi setup #used for multiple php versions <Directory / var / www > Options Indexes FollowSymLinks AllowOverride None Require all granted < / Directory > FastCgiServer / var / www / cgi-bin / php-cgi-5 .3.29 ScriptAlias / cgi-bin php / / var / www / cgi-bin / <Directory "/ var / www / cgidemo" > Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted AddHandler php-cgi .php Action php-cgi / php-cgi-bin / php-cgi-5 .3.29 <FilesMatch "\ .php $" > SetHandler php-cgi < / FilesMatch > < / Directory > ErrorLog $ {} apache_log_dir / error_cgidemo .log CustomLog $ {} apache_log_dir / access_cgidemo .log combined < / VirtualHost > |
Add the domains to / etc / hostssudo nano / etc / hosts
Add:127.0.0.1 cgidemo.dev
127.0.0.1 mysite.dev
Enable site and restart apache
sudo a2ensite cgidemo.conf
sudo service apache2 restart
If you got an error on Apache complaining about mod_fast already defined go /etc/apache2/mods-available/fastcgi.conf and comment out the last line inside the IfModule block:
1
2
3
4
5
|
<IfModule mod_fastcgi.c> AddHandler fastcgi-script .fcgi #FastCgiWrapper / Usr / lib / apahce2 / suexec #FastCgiIpcDir / Var / lib / apache2 / fastcgi < / IfModule > |
7. Test with phpinfo ()
Create new file “index.php” in “/ var / www / cgidemo /” and “/ var / www / mysite”:sudo mkdir / var / www / cgidemo /
sudo nano /var/www/cgidemo/index.php
sudo chown -R www-data: www-data / var / www / cgidemo
and
sudo mkdir / var / www / mysite /
sudo nano /var/www/mysite/index.php
sudo chown -R www-data: www-data / var / www / mysite
Put this into index.php files
1
|
<? Php phpinfo (); ?> |
Go to browser, open 2 tabs and type in domains:
mysite.dev
and
cgidemo.dev
If everything works, you shoulderstand see one tab with PHP 5.5.x and the Server API “Apache 2 handler” and one tab with PHP 3.5.29 with Server API “CGI / FastCGI”.
If you want to install more then 2 PHP versions just compile your version with phpfarm compile script and configure the virtual host.
DONE!
Sources:
https://gist.github.com/gmodarelli/5887778
https://github.com/cweiske/phpfarm
http://cweiske.de/tagebuch/Introducing%20phpfarm.htm