Building PHP with bundeled GD on Ubuntu

I was having trouble with some GD library functions not working in my PHP5.3 install on Ubuntu. Apparently Debian distributions do not compile PHP with the bundeled GD library, since it is a branch of the original GD, they consider it insecure.
To fix this problem I downloaded the sources and compiled PHP with the correct GD library.

Most of the stuff I’m about to do is from the a blog post by Ant on, so kudos there. It got me well on my way, but I still had a few issues. The first steps worked perfect:

$ cd /usr/src
$ sudo apt-get source php5
$ sudo apt-get install build-essential debhelper fakeroot
$ sudo apt-get build-dep php5
$ cd php5-5.x.x
$ sudo vim debian/rules

In this file search for “–with-gd=shared,/usr –enable-gd-native-ttf” and change it to “–with-gd=shared –enable-gd-native-ttf”.
So far so good, but running the “dpkg-buildpackage -rfakeroot” command failed on my machine, with the following error:

# start our own mysql server for the tests
/bin/sh debian/ 1025 /usr/src/php5-x.x.x/mysql_db
Timed out waiting for mysql server to be available
kill: 65: No such process

kill: 65: No such process

make: *** [test-results.txt] Error 1
dpkg-buildpackage: error: debian/rules build gave error exit status 2

This is caused because the mysql server refuses to run under root, but I had to be root to be able to build the package. After googling for a while I found the solution:

$ sudo vim debian/

In this file comment the line starting the server, and copy the command, adding the “–user=root” parameter:

# Start the daemon
#$mysqld > $datadir/run.log 2>&1 &
#add root user
$mysqld --user=root > $datadir/run.log 2>&1 &

Now the built succeeded, and after install GD worked correctly.

$ sudo dpkg-buildpackage -rfakeroot
$ dpkg -i php5-gd_5.3.5-1ubuntu7.2_amd64.deb

This should normally restart apache2, but if it does not you can do this with the services utility:

$ sudo service apache2 restart