Ubuntu 10.04 Lucid LAMP server running php 5.2 and 5.3

Note: I could not get 5.2 and 5.3 running at the same time. I could only get them both installed so where I could quickly enable one or the other.  I had to use a2enmod php5 and a2dismod php5 to turn PHP 5.2 on and off because PHP 5.3 would also take priority otherwise.

Lately I have been doing more and more Drupal development on a remote development server.  Working on the server make it easier to show the client my work and I rarely have to set anything up locally, which saves me time.  However, for a recent project I needed to debug the uc_signup module because of some errors I was getting and I didn't want to put print and die() commands on the dev server where others were working too.  I started to setup the Drupal project on my local Ubuntu computer just recently updated with 10.04 Lucid and to my surprise I was getting errors I had never seen before.  After a little investigation I realized that the errors were occuring because the code in uc_signup and calendar were not completely compatible with PHP 5.3 which is now the PHP default for Ubuntu 10.04.  I'm sure there are issues with other modules having to do with PHP 5.3 as well.

So, given the situation I decided to setup my environment to run 5.2.  However, I didn't want to remove 5.3 because I like being able to see if Drupal modules will run on PHP 5.3 as I'm sure I'll be using 5.3 in the future.  What I wanted was to run PHP 5.2 along side PHP 5.3 with as little trouble as possible.  In short, what I ended up doing was compiling PHP 5.2.13 and running it using FastCGI.  Here is the summary of steps:

(Much of these steps were taken from this excelent post on how to run PHP 5.2 and PHP 5.3 side-by-side on Mac OS X)

Download PHP 5.2.xx.  http://php.net/downloads.php

Extract PHP 5.2.xx into /opt/src.  My directory looked like this: /opt/src/php-5.2.13

Compile PHP 5.2.xx with the correct flags.

Make sure you have all the required source libraries.  I had to install the following using Synamptic Package Manager.  apt-get will of course work too.



libcurl4-gnutls-dev (or libcurl4-openssl-dev)



Configure PHP for compiling

cd /opt/src/php-5.2.13

sudo ./configure --prefix=/opt/php5.2 \
--with-config-file-path=/opt/php5.2 \
--with-mysqli \
--with-mysql \
--with-curl \
--with-gd \
--with-jpeg \
--with-jpeg-dir \
--enable-cli \
--enable-fastcgi \
--enable-discard-path \

Compile - sudo make

Install - sudo make install

Now that PHP is built I had to setup Apache to use PHP using the FastCGI module.  I installed the FastCGI module using Synaptic Package Manager.  The module name is libapache2-mod-fastcgi.  Then, I think, I enabled the FastCGI module using the command sudo a2enmod fastcgi.  It may be enabled by default after install.

This next section is where I struggled because my understanding of Apache configuration files is lacking.  But I believe only two changes to the configuration files are required.  First, I modified the /etc/apache2/sites-available/default file although I'm sure this code could go in a better location.  I then added the following lines to the top of the file:

AddHandler fastcgi-script .fcgi
FastCgiConfig -autoUpdate -singleThreshold 100 -killInterval 300
ScriptAlias /fastcgi/ /var/www/cgi-bin/

The directory /var/www/cgi-bin/ is where I put my wrapper cgi script for running PHP 5.2.  The wrapper script file I named php52.fcgi and it contained the following text:

exec /opt/php5.2/bin/php-cgi

I also set the script to be executable like so: sudo chmod +x /var/www/cgi-bin/php52.fcgi

Finally the last bit of configuration was to edit the site vhost configuration file that I wanted to run in PHP 5.2.  I added the line Action  application/x-httpd-php /fastcgi/php52.fcgi to the sites vhost file to make it look like this:

<VirtualHost *:80>
  DocumentRoot "/my/www/dir/project/httpdocs"
  ServerName project
  Action  application/x-httpd-php /fastcgi/php52.fcgi

The major cavet here is that I could not figure out a way for PHP 5.2 and PHP 5.3 to run at the same time.  This is because PHP 5.3 would alway run instead of PHP 5.2 even if I put the Action  application/x-httpd-php /fastcgi/php52.fcgi line in the vhost file.  In my situation this is OK because I'm only running the server for testing but I can see why it might be important to have both PHP versions running at the same time.  In my situation I ran the command sudo a2dismod php5 to disable PHP 5.3 and then restart Apache using sudo /etc/init.d/apache2 restart.  If I want to run PHP 5.3 again I simply run sudo a2enmod php5 and restart Apache again.

And that is all there is to it!  If you see any improvements or problems please leave a comment.  Thanks!


enable xdebug

Hi, great article

I can't enable xdebug with this metod

I edit /opt/php5.2/php.ini with

but /opt/php5.2/bin/php-cgi -m
tells me there is no xdebug module

xdebug works with php 5.3.2


xdebug for php 5.2.13

I solved from http://packages.ubuntu.com/karmic/i386/php5-xdebug/download

copy /usr/lib/php5/20060613+lfs/xdebug.so

and then fix /opt/php5.2/php.ini with

Running both simultaneously

<FilesMatch "\.php">
SetHandler application/x-httpd-php

to the virtual host should force apache to use the cgi version.

If it still doesn't work, mine is setup using "application/x-httpd-php52" which maybe makes it work since the mime type doesn't match that of the loaded php module.

One more module to enable

Thanks for the great post! I'm doing some Drupal development on a new laptop and didn't want to drop php5.3; your post allows to me to swap back and forth between 5.3 and 5.2.

One problem I ran into while following your instructions was the error: "Invalid command 'Action'" when I enabled the new php5.2 site. Apparently, I needed to enable the actions module (sudo a2enmod actions) before the fast-cgi would work.

BTW, I found that putting the AddHandler lines in the main apache2.conf file (/etc/apache2/apache2.conf) worked fine.

Thanks again!

Error "xml2-config not found"

Great Article tnx
i get errors when i try to run the configure command :

checking whether to enable LIBXML support... yes
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.

I have tried to apt-get remove libxml2 and after that apt-get install libxml2 with no success

any help will be appreciated
I use ubuntu 10.10 and run the drubuntu script to setup the machine


configure: error: libjpeg.(a|so) not found.

I got this error when running configure:
configure: error: libjpeg.(a|so) not found.

Here's an article how to get through this error

Hope this helps!

i found great installation

i found great installation instruction in this blog, found worked for me, i didnt found any post problem related to it