Recompiling PHP with gd

May 18th, 2005

Tried to use the gd image library, and I got some lovely error messages, it just didn’t recognise the functions I wanted to use.

Fatal error: Call to undefined function: imagecreate()

Cue wonderous journey through the Interweb…

For those of you who don’t know I use Slackware nearly-current (don’t ask) with a LAMP setup. This means that I don’t have some fancy packaging tool, and have compiled PHP from source. If you don’t have the sources, you’re going to find recompiling a little difficult, so have a Google around. Gentoo users have a look at the imagecreate page and scroll down.

It was very easy for me to compile PHP with gd, as they have started bundling the library with PHP since version 4.3, which luckily I have. Had a look at a very good O’Reilly article that was just the ticket. Basically all I want is JPEG support, so this worked fine for me. Haven’t tested the PNG yet.

  1. Stop Apache
  2. Move into your PHP directory
  3. > make clean
  4. > ./configure --with-apxs=/usr/local/apache/bin/apxs --with-gd --with-jpeg-dir=/usr/include --with-zlib-dir=/usr/include
  5. > make && make install
  6. Start Apache, and test it.

You’ll need to supply all the other extra parameters when you issue the configure command, for instance my “–with-apxs”. At first it did complain that it couldn’t find the zlib, if it says anything like that then just find where it is and append the “dir=” bit. If things still go wrong have a look at the aforementioned O’Reilly article.

So, I can now generate images with PHP –in the lyrics of a Snow Patrol song:

If it looks like it works and it feels like it works. Then it works.

Comments are closed.