Plugging GD into PHP, on Leopard 10.5.7

Every Mac web developer will at some time in their lives have to deal with images. Unfortunately, the PHP installation on the Leopard OS (5.2.8 as of OS X 10.5.7) doesn’t have GD compiled in by default. If you’ve tried testing web components like CAPTCHA on your Mac, and can’t render the images, that’s the reason.

First and foremost, I try to make things easy around here. Before you begin the somewhat arduous task of compiling GD (and the pre-reqs) for your Leopard-powered Mac, there is a simpler solution: the Entropy PHP Apache module from Mark Liyanage. I used Mark’s work extensively when on Tiger, and both his compilations and instructions are what I consider the gold standard in simplicity and efficiency. Unless you have XCode tools handy and are really comfortable with the terminal window, I highly recommend going that route instead. When I compiled mcrypt for dynamic loading the Entropy package wasn’t available yet, but it is now and includes mcrypt too.

For those who don’t want an additional PHP install floating around on their machine and/or like everything updated when Apple says so, here’s how you get GD running with PHP on Leopard 10.5.7…

You are going to need a few things first:

1) libjpeg, which you can pick up here (direct download from The Independent JPEG Group);

2) PHP 5.2.8 source, which you grab here (direct download from Apple Developer Connection); and

3) Xcode 3.X tools (dig through your sock drawer to find your Leopard disk, or you can download from the ADC here).

Next, create a directory at root called ‘SourceCache’ and dump the files from #1 and #2 in there and unwrap (and make sure to install XCode if you haven’t already).

Move to the jpeg-7 directory, and punch in this…

cp /usr/share/libtool/config.* .

Then each of these lines, hitting enter after each line:

mkdir -p /usr/local/include

mkdir -p /usr/local/bin

mkdir -p /usr/local/lib

mkdir -p /usr/local/man/man1

Now we’re going to compile the software. First we configure:

MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS='-arch i386 -arch x86_64 -arch ppc -arch ppc64 -g -Os -pipe -no-cpp-precomp' CCFLAGS='-arch i386 -arch x86_64 -arch ppc -arch ppc64 -g -Os -pipe' CXXFLAGS='-arch i386 -arch x86_64 -arch ppc -arch ppc64 -g -Os -pipe' LDFLAGS='-arch i386 -arch x86_64 -arch ppc -arch ppc64 -bind_at_load' ./configure --enable-shared --disable-dependency-tracking

Then we make and install:


make install

libjpeg is now installed. Next up is GD for PHP.

Move into the /php-5.2.8/ext/gd directory and type this:


Now, to configuration. Type (or copy) this:

MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure --with-zlib-dir=/usr --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/X11R6 --with-freetype-dir=/usr/X11R6 --with-xpm-dir=/usr/X11R6



make install

Second to last but certainly not least, you have to move your new shared object to a new location. Look in /php-5.2.8/ext/gd/modules directory, where you’ll find; copy/paste it into /usr/lib/php/extensions/no-debug-non-zts-20060613.

Finally, modify your php.ini file – under Dynamic Extension add the line:

…and make sure your extension directive looks like this:


Restart Apache any ol’ way you like, and voilà…


Now. Mix. Yourself. A. Cocktail. You’ve got GD.

UPDATE: The recent Apple update to 10.5.8 has no effect on this process, at least from my tests post-update. PHP is still version 5.2.8 and GD still works fine.


My hats off to you sir! Thank you for all your hard work. I feel more comfortable having one install of php and not having to worry about it breaking when I update my machine.

Oluf says:

Thanks for your effort to sort this out and share it, it’s very much appreciated.

praisebob says:

Thanks, saves loads the hassle

Miguel says:

Thank U very much! 🙂

Plugging GD into PHP, on Leopard 10.5.7 | Michael Gracie…

Plugging GD into PHP, on Leopard 10.5.7 | Michael Gracie:

Ryan says:

I followed your instructions to the letter, but I’m still showing PHP 5.2.4 without GD…
After rereading the instructions I can only think that I missed something that was “implied” but not explicitly stated – ie “create a directory at root…” I take that to be the root of my HD, and to that my info.php is showing “‘/SourceCache/apache_mod_php/apache_mod_php-44.6/php/configure’ “.

Any thoughts would be appreciated. I too was using Marc’s PHP files while in Tiger, and am trying to keep my PHP install to just a simple-built-in in the OS of this machine.

Thank you for your trouble, and time

Ryan says:

Disregard… It’s late.

Really appreciate the post.

Bhushan says:

While executing ‘make’ command in terminal i get some error
‘lipo: can’t figure out the architecture type of : /var/folders/Dz/DzC6QO5HFeqTsAxya5CK7++++TI/-Tmp-//ccyrpPva.out
make: *** [] Error 1

what can i do? Because of the error I dont get in module folder.
I am using mac 10.5.8

Looks like a driver conflict. Sorry to say, but so many drivers have been updated since 10.5 that your best bet is to update the OS first.

Leave a Reply to Ryan Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.