I have recently developed the first version of a book price comparison website, booksmarts.co.uk. It’s fairly simple, but it does depend on the simple XML parser built into PHP5.

I wasn’t sure what version of PHP was already running on my server, so I was hoping that I would just be able to drop the PHP files in and they would work straight away. As is often the case, things turned out to be more complicated than they first appeared to be. This blog entry explains what I did to upgrade PHP and its dependencies. It is primarily a record for myself, but might prove to be useful to other people trying to achieve something similar.

(Note that what follows is the order that the steps actually need to be carried out in, not the ‘try it, find unexpected dependency, install that first’ route I actually took!)


This step might not be necessary after all, but I did do it and it shouldn’t hurt. Get the latest version of binutils, needed to build the C++ compiler.

su -
mkdir archive <i>(or whatever)</i>
cd archive
wget ftp://ftp.gnu.org/binutils/binutils-2.17.tar.gz
tar -zxvf binutils-2.17.tar.gz
cd binutils-2.17
make install


wget ftp://mirrors.laffreycomputer.com/pub/gcc.gnu.org/gcc/releases/gcc-4.1.1/gcc-<b>core</b>-4.1.1.tar.bz2
wget ftp://mirrors.laffreycomputer.com/pub/gcc.gnu.org/gcc/releases/gcc-4.1.1/gcc-<b>g++</b>-4.1.1.tar.bz2
tar -jxvf gcc-core-4.1.1.tar.bz2
tar -jxvf gcc-g++-4.1.1.tar.bz2
cd gcc-4.1.1
export CFLAGS=-O0 <i>(turn off optimisation to save memory -- try building without this first)</i>
make <i>(had to shut down tomcat, which was still running, to free up enough memory for the compilation)</i>
make install


cd ~/archive
wget http://prdownloads.sourceforge.net/flex/flex-2.5.33.tar.gz?use_mirror=superb-west
tar -zxvf flex-2.5.33.tar.gz
cd flex-2.5.33
make install


PHP5 requires apache > 0.0.44, so build latest 2.0.* one [.so extensions aren’t compatible with later ones and I don’t want to rebuild these [in retrospect, I had to do this anyway, so might have been better off with a more recent apache]].

wget http://mirrors.dedipower.com/ftp.apache.org/httpd/httpd-2.0.59.tar.gz
tar -zxvf httpd-2.0.59.tar.gz
cd httpd-2.0.59
./configure --enable-rule=SHARED_CORE
/usr/local/apache2/bin/apachectl stop
make install


cd ~/archive
wget ftp://ftp.xmlsoft.org/libxml2/libxml2-2.6.27.tar.gz
tar -zxvf libxml2-2.6.27.tar.gz
cd libxml2-2.6.27
make install

PHP (finally!)

cd ~/archive
wget http://uk2.php.net/get/php-5.2.0.tar.gz/from/www.php.net/mirror
tar -zxvf php-5.2.0.tar.gz
cd php-5.2.0
<i>(./configure --help to see options)</i>
./configure --with apxs2=/usr/local/apache2/bin/apxs
make install
ldconfig <i>(may not be necessary)</i>

edit /usr/local/apache2/conf/httpd.conf to use PHP5 instead of PHP4.

Mail, etc. for PHP (i.e. PEAR)

cd ~/archive
lynx -source http://go-pear.org/ | php
pear install --alldeps Mail
[Hack &ndash; not the correct way to do this]
mv /usr/local/lib/php /usr/local/lib/php.old
ln -s /usr/share/pear /usr/local/lib/php


Other sites on the same server use a small amount of perl, so need to update mod_perl.

cd ~/archive
wget http://perl.apache.org/dist/mod_perl-2.0-current.tar.gz
tar -zxvf mod_perl-2.0-current.tar.gz
cd mod_perl-2.0.3
perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs
make install