Posted by Hill in Macintosh, Tutorials | 102 comments
Adding GD Library for Mac OS X Leopard
Thank you ever so much Alex, for pointing some inaccuracies of my post. And thank you for provide such ever an accurate and great tutorial for us.
As Alex released a really perfect tutorial for helping us to adding the GD Extension to PHP5 on OS X Server 10.5.x. I was deleted my tutorial 2 weeks ago because I don’t think my tutorial is useful anymore. And Alex is really conscientious! He has updated his tutorial again, but he seems forgot something(i’m not sure), so I write a “how to” again, any way, most of I write following is a copy of his, so, thank him again for giving us such a great stuff.
OK, So let’s get going:
1.Requirements
- You have made a backup of your system.
- You have the latest version of Apple’s Developer Tools (XCode 3.0 or higher for 10.5.x) installed. Dev Tools are available on your Server DVD and as a free download from Apple’s Developer Connection.
- X11 is installed (part of standard OS X Server install unless you deselect it)
- X11 SDK is installed (available on your OS X Developer Tools Disc or Image and part of the standard installation. This is different from the X11 client that comes with OS X.)
- You do have a backup
- You are running 10.5.x
- You have not manually updated anything related to GD, libpng, libjpeg and freetype so far (if you have, you must know how to adapt these instructions to the changes you made).
2. Getting and installing libjpeg
- 2.1 Create a temporary folder named SourceCache in your Macintosh HD
- 2.2 Download libjpeg and extract it to “SourceCache” folder.
- 2.3 Open your Terminal
Make sure you are logged in as root.
(Optional: If you don’t enable root user yet, open “Directory Utility.app” in /Applications/Utilities, and choose “Edit” option → “Enable Root User” and then, set a root password.
And Open “Terminal.app” in /Applications/Utilities, type “su” and password to login as root.)
Type:
cd /SourceCache/jpeg-6b
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
For 32-bit use:
./configure --enable-shared
For 64-bit use:
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 --enable-shared
and type this to install:
make
mkdir -p /usr/local/include
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
mkdir -p /usr/local/man/man1
make install
3. Getting and installing the GD Graphics Library extension
- 3.1 Download PHP source and extract it. (php-5.2.4 is recommended, because that is the same version with the one pre-installed in Leopard.) and copy the extracted folder to “SourceCache” folder.
- 3.2 Install GD library
type:
cd /SourceCache/php-5.2.4/ext/gd
phpize
For 32-bit use:
./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
For 64-bit use:
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
and then, type:
make
make install
4. GD extension integration
- 4.1 Modification of your php.ini file
(Please note: Apple’s stock server installation does not come with a “php.ini” file but “php.ini.default”)
If you don’t have a “php.ini” file in /etc, just rename “php.ini.default” to be “php.ini” (Administrator password required)
Add this line in php.ini file
extension=gd.so
- and search this line in php.ini (VERY IMPORTANT)
extension_dir = "./"
- DISABLE IT BY ADDING A SEMICOLON (;) IN FRONT OF THIS LINE AND SAVE CHANGE.
4.2 Edit apache2 configuration file
Open httpd.conf in /etc/apache2 and search “php5_module”
Enable it by deleting the “#” and save change.
4.3 Create a phptest.php file with the code following:
<?php
phpinfo();
?>
- and locate in /Library/WebServer/Documents.
4.4 Restart Apache and test
Open System Preference → Sharing and check the “web sharing” option
and visit http://127.0.0.1/phptest.php
If you get this, you get through, well, good luck!

Trackbacks/Pingbacks
- Macintosh - Macintosh... Its fried rice, you plick!...
- PHP w/ GD on OS X Leopard - [...] Tiger) to develop all the gallery code for a current client of mine. Luckily I stumbled across Chris’ comment ...
- Urania » Blog Archive » Making Leopard PHP a better PHP by adding GD support - [...] notes on getting PHP 5.2.5 to compile on Leopard, I discovered a fellow named Hill Pei had hacked GD ...
- GD Library with PHP on Leopard at Say the word - [...] is installed in the XAMPP package for windows. I have not installed the lib yet, but I found this ...
- GD Lib on Leopard - Success at Say the word - [...] I was a bit concerned about how many hours it would take to install the GD library. Thanks to http://www.veola.net/macintosh/adding-gd-library-for-mac-os-x-leopard ...
- Blog Rambler » Blog Archive » Development Web Server - [...] was not configured to use the GD library. After some more searching I came across another tutorial on how ...
- Getting GD into Mac OS X Leopard’s PHP at lsproc’s random pot of stuff - [...] In my work with SwishCMS, I needed GD. The best guide I found for that is http://www.veola.net/macintosh/adding-gd-library-for-mac-os-x-leopard. [...]
- GD Lib « ไร้สาระ - [...] GD ต่อโดยการลงก็ทำตามขั้นตอนใน Adding GD Library for Mac OS X Leopard (ลืมบอกไปผมใช้ MacOS X Leopard [...]
- cthrall.com » Blog Archive » Installing GD PHP Extension on a MacBook Pro - [...] I’ve got XCode installed on my MBP, so you’ll need that. Then, follow the instructions in this great post. ...

I had the same problem as almost everybody through these comments.. everything installed, nothing happened.
Apache error_log gave /usr/lib/php/extensions/no-debug-non-zts-20060613/gd.so’ – (null) in Unknown on line 0, while PHP command line gave dyld: NSLinkModule() error
dyld: Symbol not found: _php_sig_gif
Referenced from: /SourceCache/php-5.2.4/ext/gd/modules/gd.so
Expected in: flat namespace.
I first installed everything on a first generation MacBook (i.e. 32-bit) then attempted on one of the new MacMinis (64-bit). The MacBook install worked on the first attempt, while the MacMini tok some attempts. After realizing it was a 64-bit, I gave it another try using the other instructions and sudo-ing every command.. No luck.
Doing a software update grabbing PHP-5.2.5, and using this source instead of the PHP-5.2.4, I decided to enable the sudo user through the Directory Utility’s Edit menu and logging in using sudo su. I followed the 64-bit instructions one last time, and it works like a charm:)
Great work guys!
Simply absolutely plain perfect
Thank you very very very much for this real time saver tutorial.