Richard
If you want to do some graphics work within PHP you will need the GD library. It will take several steps of preparation before you can add this to PHP.
First you need to install X11, you can find this in the file InstallESD.dmg from the Mountain Lion installer package. How to find it, read this. This because you need to get an optional installer package if you want to use GD. Mount the disk image and install the file from Packages called X11redirect.pkg
To complete X11 you need to download and install the XQuartz X11 server.
Secondly you need to download the source code from the Freshmeat libjpeg project. Unpack the source code and then go into the newly created folder and execute the following commands:
export MACOSX_DEPLOYMENT_TARGET=10.8 ./configure --enable-shared
Next follow with the commands:
make sudo make install
To compile and install the library.
Next step is to recompile the php installation as described on this page: Compiling PHP.
The only change you need to make is to add:
--with-jpeg-dir=/usr/local/lib \ --with-png-dir=/usr/X11R6 \ --with-freetype-dir=/usr/X11R6 \ --with-xpm-dir=/usr/X11R6 \
To the configure statement and it will include this library for you.
For example:
./configure --prefix=/usr/local/php5 \ --mandir=/usr/share/man \ --infodir=/usr/share/info \ --sysconfdir=/etc \ --with-config-file-path=/etc \ --with-zlib \ --with-zlib-dir=/usr \ --with-openssl \ --without-iconv \ --enable-exif \ --enable-ftp \ --enable-mbstring \ --enable-mbregex \ --enable-sockets \ --with-mysql=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-gd \ --with-jpeg-dir=/usr/local/lib \ --with-png-dir=/usr/X11R6 \ --with-freetype-dir=/usr/X11R6 \ --with-xpm-dir=/usr/X11R6 \ --with-apxs2=/usr/local/apache2/bin/apxs



Comments
11:47 am
X11 is not bundled with Mountain Lion. You are redirected here to get the installer.
http://xquartz.macosforge.org/landing/
7:01 pm
@George, X11 is included in Mountain Lion. It’s in the install disk image under the additional packages. I had noted it in the progress blogpost but I’ve now added how to get this to this page as well.
10:35 pm
The configure statement has dropped –with-gd that was used in Lion. Was this intentional?
5:39 am
@Bruce, yes intentional . It caused errors on my Mac during the configuration fase, I’m still trying to find out why.
3:29 am
Hey Richard,
I managed to get GD working.
Adding ‘–with-gd’ got an error about ‘png.h’ missing. X11 is installed as you suggest rather than the xquartz option. I tried the bundled PHP that came with Mountain Lion and found that GD was working so I looked at the configuration.
–with-gd
–with-freetype-dir=/BinaryCache/apache_mod_php/apache_mod_php-78~13/Root/usr/local
–with-jpeg-dir=/BinaryCache/apache_mod_php/apache_mod_php-78~13/Root/usr/local
–with-png-dir=/BinaryCache/apache_mod_php/apache_mod_php-78~13/Root/usr/local
I searched around for this path and came across:
http://opensource.apple.com/source/apache_mod_php/apache_mod_php-78/
So I grabbed freetype, libjpeg and libpng and compiled them. Then compiled php (5.3.15) with:
–with-jpeg-dir=/usr/local/lib \
–with-png-dir=/usr/local/lib \
–with-freetype-dir=/usr/local/lib \
–with-xpm-dir=/usr/X11R6 \
This gave an error about libXpm. I couldn’t find anything about this library so I just dropped it from the config.
PHP happily compiled and GD is now enabled.