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.sudo
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.
libxml2-dev
libmysqlclient-dev
libcurl4-gnutls-dev (or libcurl4-openssl-dev)
libpng12-dev
libjpeg62-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 \
--enable-force-cgi-redirect
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:
#!/bin/sh
PHP_FCGI_CHILDREN=1
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
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
</VirtualHost>
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!
Sources:
enable xdebug
Hi, great article
I can't enable xdebug with this metod
I edit /opt/php5.2/php.ini with
zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
but /opt/php5.2/bin/php-cgi -m
tells me there is no xdebug module
xdebug works with php 5.3.2
Thanks
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
zend_extension=/usr/lib/php5/20060613+lfs/xdebug.so
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"