30 Sep 2004, 12:26 p.m.

HOWTO: Install PHP5 on Linux

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.

Apache

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 \\
    --enable-shared=max

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.

Zlib

These are the compression libraries on which PHP is built, so they're fairly important. Zlib is available from http://www.gzip.org/zlib/.


wget http://www.gzip.org/zlib/zlib-1.2.1.tar.gz
tar -zxvf zlib-1.2.1.tar.gz
cd ./zlib-1.2.1
./configure --prefix=/usr/local/
make
make install

Libiconv

Details available from http://www.gnu.org/software/libiconv/.


wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.9.2.tar.gz
tar -zxvf libiconv-1.9.2.tar.gz
cd libiconv-1.9.2
./configure --prefix=/usr/local/
make
make install

Libxml2

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


wget http://xmlsoft.org/sources/libxml2-2.6.15.tar.gz
tar -zxvf libxml2-2.6.15.tar.gz
cd libxml2-2.6.15
./configure --prefix=/usr/local/ \\
    --with-zlib=/usr/local/ \\
    --with-iconv=/usr/local/
make

Libxslt

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 xmlsoft.org.


wget ftp://xmlsoft.org/libxslt-1.1.12.tar.gz
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/ \\
    --with-libxml-libs-prefix=/usr/local/lib/
make
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.


wget http://heanet.dl.sourceforge.net/sourceforge/ming/ming-0.3beta1.tar.gz
tar -zxvf ming-0.3beta1.tgz
cd ming-0.3beta1/
make
mv libming.so libming.so.0.3beta1
make install

GD

For dynamic image generation. Details from http://www.boutell.com/gd/. 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.

libjpeg

http://www.ijg.org/.


wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar -zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure
make
make install

libpng

http://libpng.sourceforge.net/. 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.


wget http://heanet.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.5.tar.gz
tar -zxvf libpng-1.2.5.tar.gz
cd libpng-1.2.5
cp scripts/makefile.linux makefile
make
make install

PHP

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.


wget http://uk.php.net/get/php-5.0.3.tar.gz/from/this/mirror
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
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.

Posted by Simon in