How to install PHP 5.3 next to 5.2.x or 4.x?

Daniel Urstöger
05-08-2010 12:31

There are certain ways to achieve this, since the main reason for me doing that is testing, I choose the way with the least effort and added PHP 5.3 via CGI to Apache, next to the already installed PHP 5.2.x modul.
So here are the steps to get you started:

aptitude install subversion build-essentials
cd /usr/src
svn co http://svn.php.net/repository/pear/ci/phpfarm/trunk/ phpfarm
cd phpfarm/src

  Now you might want to edit config options in options.sh according to your needs, I added mysql and pdo_mysql:

#gcov='--enable-gcov'
configoptions="\
--enable-bcmath \
--with-mysql \
--with-curl \
--with-png \
--with-gd \
--enable-gd-native-ttf \
--with-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-zlib \
--with-jpeg-dir=/usr/lib \
--with-xpm-dir=/usr/lib \
--with-freetype-dir=/usr/lib \
--with-gettext \
$gcov"

After you have done this, you can start with the compilation:

./compile.sh 5.3.2

As you already guessed this compiles PHP version 5.3.2, if you need a different version, you just change the line accordingly. Once the compilation completes we now need to tell Apache a few things:

a2enmod actions

This enables the actions module, which we need for our purposes. Next we need to edit a few config files, we start with /etc/apache2/mods-enabled/actions.conf, open it with your favorite editor and add the following lines:

    Options ExecCGI
    AllowOverride None


ScriptAlias /cgi-php532/   /usr/src/phpfarm/inst/bin/
Action php532-cgi /cgi-php532/php532-cgi 

  Now we need to create a wrapper file for php-cgi, so open/created /usr/src/phpfarm/inst/bin/php532-cgi and put that into the file:

#!/bin/sh 
/usr/src/phpfarm/inst/php-5.3.2/bin/php-cgi "${PATH_TRANSLATED}"

The wrapper script needs to be made executeable:

 

chmod +x /usr/src/phpfarm/inst/bin/php532-cgi

That´s already most of the job. As you most certainly already realized you could add more version of PHP next to each other, just by following this steps, e.g. you could also add 5.2.x or any other version you might need.

To activate PHP 5.3.2 for a specific vhost you can either add this to a .htaccess file or the vhost in question:

 

AddHandler php532-cgi .php

done.


So what would you need to do to get another PHP version into the same setup? 

cd /usr/src/phpfarm/src
./compile 5.2.13 

Add the according values into /etc/apache2/mods-enabled/actions.conf:

ScriptAlias /cgi-php5213/   /usr/src/phpfarm/inst/bin/
Action php532-cgi /cgi-php5213/php5213-cgi 

Create the file /usr/src/phpfarm/inst/bin/php5213-cgi:

#!/bin/sh 
/usr/src/phpfarm/inst/php-5.2.13/bin/php-cgi "${PATH_TRANSLATED}"

 Now make that file executable:

chmod +x /usr/src/phpfarm/inst/bin/php5213-cgi

And from here you can now enable PHP 5.2.13 on a vhost just as before via .htaccess or the Apache config like:

AddHandler php5213-cgi .php

Enjoy! 

 




 

Average rating: 0 (0 Votes)

You cannot comment on this entry