Recompiling PHP5 With Bundled Support For GD On Ubuntu

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Submitted by patusovniak (Contact Author) (Forums) on Tue, 2009-07-28 11:36. :: Ubuntu | PHP

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!


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Paul Stenning (not registered) on Sun, 2010-01-10 15:52.

I have just completed this on a fully up to date Ubuntu 8.04 LTS server.  Excellent post, works really well! 

Two minor changes were needed because it had a slightly later version of PHP installed.

  • The directory name is now php5-5.2.4
  • The compiled package name is now php5-gd_5.2.4-2ubuntu5.9_i386.deb
Submitted by Leszek (not registered) on Wed, 2009-08-05 13:58.
In case of dependency problems, apt-get -f install should sort things out.
Sponsored Links: Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com

One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com

One Number. One Voicemail.
Make it easier for clients to reach you. Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com

One number. One voicemail. Sprint Mobile Integration.
www.seamlessenterprise.com

AT&T Synaptic Compute as a Service. Boost your power on demand.

Trial: IBM Cognos Express Reporting, Analysis & Planning