Running PHP 5.3 and 5.2 in parallel with nginx

The problem: you want to upgrade your Ubuntu server, but you still need PHP 5.2 for some old web sites (i.e. Drupal 5 is not PHP 5.3 compatible).
The solution: Go with the packaged PHP 5.3 for your new sites and compile PHP 5.2 yourself for the old ones. As we use the nginx webserver with FastCGI, we can choose per site which PHP CGI binary will handle the requests.

The following steps were carried out on Ubuntu 10.10.

  • Download PHP 5.2 from
  • Extract the archive (tar xvzf php-5.2.X.tar.bz2)
  • Change to the new directory (cd php-5.2.X)
  • Run the configure script, we used the following options ("php52" is the name for configuration/data directories, instead of "php5" used by the ubuntu package):
./configure --prefix=/usr/share/php52\
 --localstatedir=/var \
 --disable-debug \
 --with-regex=php \
 --disable-rpath \
 --disable-static \
 --with-pic \
 --with-layout=GNU \
 --with-pear=/usr/share/php \
 --enable-calendar \
 --enable-sysvsem \
 --enable-sysvshm \
 --enable-sysvmsg \
 --enable-bcmath \
 --with-bz2 \
 --enable-ctype \
 --with-db4 \
 --without-gdbm \
 --with-iconv \
 --enable-exif \
 --enable-ftp \
 --with-gettext \
 --enable-mbstring \
 --with-pcre-regex=/usr \
 --enable-shmop \
 --enable-sockets \
 --enable-wddx \
 --with-libxml-dir=/usr \
 --with-zlib \
 --with-kerberos=/usr \
 --with-openssl=/usr \
 --enable-soap \
 --enable-zip \
 --with-mhash=yes \
 --with-exec-dir=/usr/lib/php5/libexec \
 --without-mm \
 --with-curl=shared,/usr \
 --with-zlib-dir=/usr \
 --with-gd=shared,/usr --enable-gd-native-ttf \
 --with-gmp=shared,/usr \
 --with-jpeg-dir=shared,/usr \
 --with-xpm-dir=shared,/usr/X11R6 \
 --with-png-dir=shared,/usr \
 --with-freetype-dir=shared,/usr \
 --with-ttf=shared,/usr \
 --with-t1lib=shared,/usr \
 --with-ldap=shared,/usr \
 --with-ldap-sasl=/usr \
 --with-mysql=shared,/usr \
 --with-mysqli=shared,/usr/bin/mysql_config \
 --with-pspell=shared,/usr \
 --with-unixODBC=shared,/usr \
 --with-xsl=shared,/usr \
 --with-snmp=shared,/usr \
 --with-sqlite=shared,/usr \
 --with-mssql=shared,/usr \
 --with-tidy=shared,/usr \
 --with-xmlrpc=shared \
 --enable-pdo=shared \
 --without-pdo-dblib \
 --with-pdo-mysql=shared,/usr \
 --with-pdo-odbc=shared,unixODBC,/usr \
 --with-pdo-pgsql=shared,/usr/bin/pg_config \
 --with-pdo-sqlite=shared,/usr \
 --with-pdo-dblib=shared,/usr \
 --enable-force-cgi-redirect --enable-fastcgi \	
  • The configure script may require additional dev-libraries, install them (incomplete list, you may reuqire others, too):
aptitude install libxml2-dev libpcre3-dev libbz2-dev libcurl4-openssl-dev libgdbm-dev libdb-dev libjpeg62-dev libpng12-dev libxpm-dev
  • Next execute
  • Now we can create a package from that and install it:
sudo checkinstall
  • Create the config directory /etc/php52 and copy/link the configuration files from /etc/php5
sudo mkdir /etc/php52
sudo ln -s /etc/php5/conf.d /etc/php52
sudo ln -s /etc/php5/cli /etc/php52
  • Now you can use /usr/bin/php52/php-cgi in your upstart/init script as PHP 5.2 binary. You should also have now a deb-package in the directory where you executed checkinstall. You can use that package on other servers as well (installation: sudo dpkg -i php-5.2.deb).



I followed the steps described above, but after the compilation shared modules (.so) are missing - only .a and .la files are present in modules/ directory.  Do you have any idea where could be the problem?