Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

Recompiling PHP5 With Bundled Support For GD On Ubuntu


I’ve been installing the LAMP stack on an Ubuntu based server for a client. They rely on the version of LibGD that’s bundled with PHP5. This version includes certain functions including imagerotate() and others.

It seems that the people who build Ubuntu (and Debian) distribution do not want to compile PHP5 with the version of GD that comes bundled with PHP5. As far as I can tell the guys at Ubuntu (and Debian) consider this to be a fork of the original GD library and think that this could be a security risk. Their stance on it is that if PHP want to use this version then they should contribute the changes that have been made to the original GD library back to the core project. This seems fair enough, but unfortunately I can’t immediately change the direction of an open source project this big – or probably any project, come to think about it!

After a bit of rummaging around on the Internet I found nothing to do with actually compiling in this support, so I tried to work out how to do this… In theory! I found a link on Ubuntu forums about including the GMP library I roughly followed this through.

To install the required packages and download the source code for PHP5:

Install build tools, debian helpers and fakeroot:

apt-get install build-essential debhelper fakeroot

Source code should reside in /usr/src:

cd /usr/src

Download PHP source:

apt-get source php5

Install all packages required to build PHP5:

apt-get build-dep php5
cd php5-5.2.3

Now a package is compiled is set within the files contained in the debian directory of a package. Rules for configuring the compile process can be found in debian/rules. In this file there is a line that reads –with-gd=shared,/usr –enable-gd-native-ttf \. This links to the Ubuntu distributed version of LibGD as a shared library. It is part of the autoconf script that customises the compilation of PHP. I replaced this line with –with-gd=shared –enable-gd-native-ttf \. This causes the compilation process to use the bundled version of GD and make a shared library.

Once the package has been reconfigured it can be compiled and installed by:

Build the php5-* packages:

dpkg-buildpackage -rfakeroot
cd ..

Install the new php5-gd package

dpkg -i php5-gd_5.2.3-1ubuntu6.3_i386.deb

A quick

/etc/init.d/apache2 restart

and hey presto, you should be using the bundled version of LibGD for PHP. Hurrah!

 

Comments

comments