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

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:

phpize

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

Then..

make

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 gd.so; 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:

extension=gd.so

…and make sure your extension directive looks like this:

extension_dir=/usr/lib/php/extensions/no-debug-non-zts-20060613

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

gd-phpinfo

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.

Did this tutorial save you immeasurable amounts of time and money, while simultaneously eliminating a frustration that very likely caused at least three [dozen] of your hair follicles to come loose?

Signs say yes (or at least it made you smile), so why don't you click HERE.

Comments

  1. 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

  2. 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: *** [gd.la] Error 1

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

Trackbacks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>