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:
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
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
gd.so; copy/paste it into
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.