HOWTO: Install PHP5 on Linux

Posted on Thursday, the 30th of September, 2004.

Tagged: , and

I did this on a IBM box running Red Hat Linux, I'm not sure which version. It basically went like a dream, and maybe took an hour or so. This is to compile PHP5 as an Apache module, a way I choose as it makes subsequent PHP upgrades simpler. Everything was installed under /usr/local, for what it's worth.

By way of a disclaimer, do follow the advice with caution. I make no guarantees that this will work for you, or that it won't severely compromise your system, or whatever. Also, note that PHP5 is not yet at a stable release and so you'd be a fool to put this into a production environment. So be careful. Ok, enough chat, let's go!

Update 2004/10/07: PHP is now at version 5.02. We're using it in production here, and everything seem to be going smoothly.


Firstly you'll want Apache HTTPD up and running. There's enough documentation on that all over the web so I won't linger here, except to point out that since I want PHP as an Apache module, my configure line looks like so:

./configure --prefix=/usr/local/apache \
    --enable-module=rewrite \
    --enable-shared=rewrite \

Secondly there's a whole stack of libraries to get hold of and install. I may have overdone it but I wanted to make sure I had the lot. All versions were the latest available at the time, unless otherwise stated.


These are the compression libraries on which PHP is built, so they're fairly important. Zlib is available from

tar -zxvf zlib-1.2.1.tar.gz
cd ./zlib-1.2.1
./configure --prefix=/usr/local/
make install


Details available from

tar -zxvf libiconv-1.9.2.tar.gz
cd libiconv-1.9.2
./configure --prefix=/usr/local/
make install


Libxml2 is the core of PHP5's greatly improved XML processing. Downloads page: Put the kettle on: this is one of the lengthier builds, as it's pretty large bundle to compile.

tar -zxvf libxml2-2.6.15.tar.gz
cd libxml2-2.6.15
./configure --prefix=/usr/local/ \
    --with-zlib=/usr/local/ \


We won't be seeing Sablotron in PHP5 for some time, so we're using libxslt, which is much faster anyway. This is also from

tar -zxvf libxslt-1.1.12.tar.gz
cd ./libxslt-1.1.12
./configure --prefix=/usr/local/ \
    --with-libxml-prefix=/usr/local/ \
    --with-libxml-include-prefix=/usr/local/lib/ \
make install

Ming (0.3b)

Ming is a very powerful, but still rather experimental library which allows you to generate SWF (Flash) format files. At the time of writing the latest version was 0.3b which compiled pretty well (although the bundled INSTALL instructions are entirely misleading). There's no autoconf for this one, so just make and make install straight off. The one gotcha was that make install seems to want to install a file that does not exist - hence the mv line.

tar -zxvf ming-0.3beta1.tgz
cd ming-0.3beta1/
make install


For dynamic image generation. Details from Recent PHP support for GD now makes installation a breeze, though in order to do anything useful, you'll require at least the following libraries.


tar -zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
make install

libpng Slightly odd this one, so take care. There's no configure but you need to make sure you get the right makefile for your system.

tar -zxvf libpng-1.2.5.tar.gz
cd libpng-1.2.5
cp scripts/makefile.linux makefile
make install


And finally configure and install PHP itself. At the time of writing PHP version 5.0.3 is the latest. I'll try to update this page for subsequent releases, but no promises.

tar -zxvf php-5.0.3.tar.gz
cd php-5.0.3
./configure --prefix=/usr/local \
    --with-apxs=/usr/local/apache/bin/apxs \
    --with-ming=/usr/local \
    --with-gd --with-jpeg-dir=/usr/local \
    --with-png-dir=usr/local \
    --enable-gd-native-ttf --with-xml \
    --with-libxml-dir=/usr/local \
    --with-expat-dir=/usr/local/lib \
    --with-dom=/usr/local \
    --enable-ftp \
    --with-mysql=/usr/local \
    --enable-shared=yes \
    --enable-static=yes \
    --with-xsl=/usr/local \
    --enable-track-vars \
    --enable-sockets --enable-wddx \
    --with-xmlrpc \
    --with-zlib-dir=/usr/local/include \
    --with-iconv --enable-soap 
make install

The PHP install takes the liberty of reconfiguring your Apache for PHP5. I'm not sure I'm entirely comfortable with that idea, but it seems to work. You may need to restart your httpd though, and like the installer says, you might choose to add /usr/local/lib/php to your include_path in php.ini.


Enter your comment: