GD Graphics Library - Building into PHP

The following is the one and only email (despite several requests) that we have
received that describes the approach used to build GD into PHP; I make no
assertions as to it's correctness, but it has worked for at least one user!

Note that these instructions relate to the unpatched version. This document
will be updated if and when we get a confirmed approach for building the
patched version (any volunteers?).

The GD patches can be found at

It was generously submitted by Bradley Baumann
( and is copied here
unedited. Although I may have stuffed up some of the formatting.

If you have any questions please send them to Bradley (, and if you wish to expand or update the build instructions, please submit them to

sure... well, I've been working on getting GD
working with PHP for almost the entire day today. I finaly did get

This is EXACTLY how it was done :

1st. Downloaded the GD Libs, extracted em.
2nd. Downloaded JPEG-6B Libs. ( I believe that's what they are called )
3rd. Downloaded ZLIB. (Already had this one installed)
4th. Downloaded PNGLIB.
5th. Built JPEG-6B. (make, make install)
6th. Built ZLIB.(make, make install)
7th. Built PNGLIB.
(make, make install)
*note: the JPEGLIB, ZLIB and PNGLIB are listed as REQUIRED to download ALREADY, from the GD site, but most people don't follow directions. Heh.*
Now comes the "tricky" part, I tried to "make" GD, but I don't some error about FreeType stuff. So I modified the Makefile, and removed the TTF and FreeType thing from the LIBS, leaving the LIBS= Lines like this :
LIBS=-lgd -lpng -lz -ljpeg -lm

I then RE-RAN make, and everything went fine.
Now that the MAKE was done, I went on to the MAKE INSTALL. This went perfectly.
Since they were all installed properly, I went on to the PHP installation.

PHP Installations can be a bit tricky. But this is how its done :
If you already have a webserver installed (Apache is the most commonly used) you do this (while in the php-4.x.x) directory (the one with the install files) :

./configure --with-mysql
--with-gd=/home/prophet/gd-1.8.4 --with-jpeg-dir=/home/prophet/jpeg-6b

the --with-gd option, tells PHP to install it with GD. Following that option, you need to include the directory in which the INSTALL FILES are located. Mine were in /home/prophet/gd-1.8.4

Next comes the --with-jpeg option, this allows PHP to have access to the JPEG functions (ImageJPEG, etc) again, that needs to point to the JPEG-6B INSTALL DIRECTORY. Not where it INSTALLED TO, where the INSTALL FILES ARE LOCATED.

Then, you must have the apxs option. --with-apxs= is CRUCIAL. You need this. Point it to where your apache is INSTALLED TO. There is no need to recompile apache, if you use this. My apache was installed to /www , so I pointed it to /www/bin/apxs    (some people may have a problem here, and if they do, its because they did not install apache with

Here is the ideal Apache, and PHP installation:

1.  gunzip apache_xxx.tar.gz
2. tar -xvf apache_xxx.tar
3.  gunzip php-xxx.tar.gz
4.  tar -xvf php-xxx.tar
5.  cd apache_xxx
6.  ./configure --prefix=/www --enable-module=so
7.  make
8.  make install
9.  cd ../php-xxx
10. ./configure --with-mysql --with-apxs=/www/bin/apxs
11. make
12. make install

  If you decide to change your configure options after installation
  you only need to repeat the last three steps. You only need to:
  restart apache for the new module to take effect. A recompile of Apache is not needed.

11. cp php.ini-dist /usr/local/lib/php.ini

  You can edit your .ini file to set PHP options.  If you prefer this file in another location, use:
 --with-config-file-path=/path in step 8.

12. Edit your httpd.conf or srm.conf file and check that these lines are present and not commented out:

   AddType application/x-httpd-php .php
   LoadModule php4_module libexec/

 You can choose any extension you wish here. .php is simply the one we suggest. You can even include .html, and .php3 can be added for backwards compatibility.

 The path on the right hand side of the LoadModule statement must point to the path of the PHP module on your system. The above statement is correct for the steps shown above.

13. Use your normal procedure for starting the Apache server. (You must stop and restart the server, not just cause the server to reload by using a HUP or USR1

Once PHP is ./configured properly - You need to make, and make install. There should be no issues there.

Finally, if you have Apache running, you need to restart it, by doing a apachectl restart. (/www/bin/apachectl restart)

I hope this helps you out!
I'll let you know if I get the patched version working! Keep in mind that I'm running OPENBSD 3.0. I'm almost positive that this will work on most other flavors of *nix, but just incase : is
a good place for PHP installation help.