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
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
sudo ./configure --prefix=/opt/php5.2 \
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/
/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:
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:
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!