ilovett

Installing PHP5 From Source on Debian testing

February 16th, 2005

Ever since PHP5 came out, I've been waiting for Debian packages to appear in testing that would make upgrading from PHP 4 easy, easy in that apt-get kind of way that Debian users know and love. But no dice. For whatever reason, PHP5 hasn't made it into testing yet. I got tired of waiting, so I decided to take the plunge and do the install myself from source. It went a little something like this.

First things first: download the source code and unpack it. I opted to use /opt for this; it was empty (don't even try to deny the quality of that pun). Next, plan which extensions to include. If you're used to looking at the phpinfo() output from Debian's php4 packages, you might have noticed that just about everything under the sun is compiled as a shared extension. I don't need quite that much flexibility, so I decided to stick to the basics. I knew I needed/wanted Apache2 support and MySQL support, for instance. I also wanted to scope out some of the XML-related fanciness in PHP5, such as XSL. So let's see what the config options are:

$ ./configure --help
If you're like me, you may get kid-in-candystore syndrome-- "I want this, and that, and that, and that..." I ended up with the following:
./configure --prefix=/usr/local/ --with-apxs2=/usr/bin/apxs2 --with-mysql=shared,/usr
 --with-xsl --enable-soap  --with-curl=shared,/usr --with-pgsql --enable-wddx
--with-gd=shared,/usr --enable-gd-native-ttf --with-jpeg-dir=shared,/usr
--with-png-dir=shared,/usr --with-freetype-dir=shared,/usr --with-imap=shared,/usr
 --with-imap-ssl --with-ttf=shared,/usr --with-t1lib=shared,/usr --with-zlib --with-kerberos

To get the configure command to make it all the way through (if the last line of output doesn't thank you for using PHP, you didn't make it) I had to install a bunch of -dev packages. This is where the candystore syndrome would come back to bite you if you weren't using Debian. But you are, so no biggie. I set the install prefix to /usr/local so I wouldn't disturb the php4 installation under /usr/bin. I set --with-apxs2 because I run Apache2, and it was already on my PHP 4 phpinfo() page so I just copied it over. However, the configure script resisted until I installed the apache2-prefork-dev package.

The other packages followed the same pattern, since I was mostly taking stuff I already had from PHP4 and making sure it made it into my spiffy new PHP5 build. Identify interesting extension; copy the config option from PHP4's info page or from the config help, apt-cache search for an appropriate *-dev package (postgresql-dev, libxslt1-dev, libxml2-dev, etc) and pull down any additional packages as needed. The imap-related extensions were a little weird because they need a package called libc-client-dev, and that in turn somehow requires you to add --with-kerberos. I don't make the rules, I just follow them.

If only that were the end of it. But it's not. Now we make!

$ make

And in the meanwhile we find something interesting to read on the web. Once make is done and displays the "Build complete" message, it's time for

$ make install

Let's capture the output for posterity:

Installing PHP SAPI module:       apache2handler
/usr/share/apache2/build/instdso.sh SH_LIBTOOL='/usr/bin/libtool' libphp5.la /usr/lib/apache2/modules
/usr/bin/libtool --mode=install cp libphp5.la /usr/lib/apache2/modules/

cp .libs/libphp5.so /usr/lib/apache2/modules/libphp5.so
cp .libs/libphp5.lai /usr/lib/apache2/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /opt/php-5.0.3/libs'
chmod 644 /usr/lib/apache2/modules/libphp5.so
[activating module `php5' in /etc/apache2/httpd.conf]
Installing PHP CLI binary:        /usr/local//bin/
Installing PHP CLI man page:      /usr/local//man/man1/
Installing shared extensions:     /usr/local//lib/php/extensions/no-debug-non-zts-20041030/
Installing PEAR environment:      /usr/local//lib/php/
[PEAR] Archive_Tar    - installed: 1.1
[PEAR] Console_Getopt - installed: 1.2
[PEAR] PEAR           - installed: 1.3.3
Wrote PEAR system config file at: /usr/local//etc/pear.conf
You may want to add: /usr/local//lib/php to your php.ini include_path
[PEAR] XML_RPC        - installed: 1.1.0
Installing build environment:     /usr/local//lib/php/build/
Installing header files:          /usr/local//include/php/
Installing helper programs:       /usr/local//bin/
  program: phpize
  program: php-config
  program: phpextdist

Looks like it would be apropos to run some sort of libtool command:

libtool --finish /opt/php-5.0.3/libs

Also worth noticing is the fact that the php5 extension has been enabled in Apache's httpd.conf for us already. How considerate. But it's not done "the Debian way", so pop open your httpd.conf file (still assuming Apache 2, mind you), comment out the mod_php5 line at the top that was inserted by make, and save. Then pay a visit to the mods-available folder, and copy php4.load and php4.conf into similarly named files for php 5. Edit them too. Finally:

$ a2dismod php4
$ a2endmod php5

I had high hopes of being able to run PHP 4 and 5 under the same Apache server without having to de-promote one to cgi status, but no dice. So I bit the bullet and went with PHP 5. The way I figure it, I have other machines that could run PHP 4 if I really needed to.