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!


@Michael
your mac is a 64 bit machine ? if this is the case, run “make clean” in the Terminal and following the 64 bit instruction. try again.
@Hill –your mac is a 64 bit machine ?
Are you SERIOUS?
no. I don’t have enough money to change a 64 bit machine
Hi,
thanks for the article. This is almost identical except to another article @ http://osx.topicdesk.com/content/view/135/62/. (Found that one through the Apple Forums.)
However, to all the people that are having problems with GD not being installed (like I was), there is one small but significant difference in the installation instructions.
“Also, if you already had your own php.ini, make sure the
extension_dir= setting is not overriding any defaults. If in doubt,
comment it out or point to the directory gd.so was installed into (usually
/usr/lib/php/extensions/no-debug-non-zts-20060613)”
My extension_dir line reads:
extension_dir = “/usr/lib/php/extensions/no-debug-non-zts-20060613″
As Hill says, the “./” is a problem for some reason and I had to remove it. But this process he takes us through puts the gd.so in the above directory and it needs to be included. Once I did this, it all worked great! Thanks to both authors for a diligent and thorough write-up.
hey folks
i would like to thank you for the article. On my desktop imac I follow the article’s instruction to install the GD extension NP.
However when I tried it on my macbook pro I cannot get it working. It turns out I have my previous darwin installation having the path /opt/local preceding other PATH.
In order to avoid this problem make sure you do a which on phpize and ensure its path is /usr/bin/phpize.
Also make sure your PATH variable does not contain the /opt/local ….
I hope this helps.
Best Regards,
Bruce
@Hill
Thanks a lot for your appreciation !
Hello I tried to download the file php5.leopard.20071101.tar.gz from the link above but its gone now.
I am in the same boat, I cant get GD Library to come up.
Thanks for great tutorial. It was very helpful. Got stuck when I used 32bit instead of 64bit. Maybe a note or link at in the tutorial to explain the difference. Thanks!! -enrique
I’ve tried for a while to get this to work without any progress. Is anyone able to make a package for the GD library? ‘Cause this is just too frustrating.
Ok, it’s working better…
I have a Intel Core2Duo MacBook Pro. I’m a bit confused… Do I select the 32bit or 64bit installation?
Doing the 64bit installation did the job. Just had to restart my Mac. GREAT WORK!!!
Um, how do I remove XCode?
@ sebz
oh. no no no no….
please don’t uninstall your Xcode, because the Xcode is not only a developing tool but also a runtime library, it means, Xcode package installs some libraries you need, for example libpng, and your GD running needs libpng.
I think GD wouldn’t work if you uninstall XCode.
If you want to try a quick solution as mentioned in an earlier post.. there is now version 6 of march lynairges packages which adds GD amoungst others Leopard systems. Had it up and running in about 5 minutes…
http://www.entropy.ch/phpbb2/viewtopic.php?t=2945&postdays=0&postorder=asc&highlight=leopard&start=0
Fyi, there are myslq connection issues with the latest entropy beta 6 for ppc and/or 32 bit. Also, this is the correct line to put in httpd.conf if you are going to use the entropy build – the path Chris gave above is not correct.
LoadModule php5_module /usr/local/php5/libphp5.so
I dont’ get this … I spent about 5 hours on this and I still can’t get it working… main problem my standard leopard /w all the x11 stuff installed doesn’t have X11R6 dir why does your command reference that directory when it doesn’t come with it? txs
thank you. i spent ages trying to work out how to do this and i kept getting compile errors or just plainly not working. finally after following the instructions on this page i got it working! thanks again!
I encountered the same issue Chris and Glen did, i.e. the instructions went smoothly but there was no sign of gd in the phptest.php.
Before I try Chris’s ‘entropy’ solution, I saw SebZ’s comment about 32/64 bit. I have Intel Core 2 Due and it seems from reading the above that I should have used the 64-bit version. . . oops.
If I want to go back and try the 64-bit version, how much of what I’ve done do I need to undo, and how do I do it? As it stands I’ve completed the entire instructions above (32 bit versions) and closed down everything (Terminal etc).
Thanks for any advice!
Thanks a lot for your great tutorial. For me it worked!
Thanks again.
Thanks a lot for your help! It worked like a charm!
Cheers!
This was a well written tutorial, but I did have some problems.
The GD directory does not show up in PHP.
I opened the error_log and this is what I got:
% Digest: generating secret for digest authentication …
% Digest: done
% Apache/2.2.6 (Unix) mod_ssl/2.2.6 OpenSSL/0.9.7l DAV/2 PHP/5.2.4 configured — resuming normal operations
% File does not exist: /Library/WebServer/Documents/favicon.ico, referer: http://localhost/phpinfo.php
% SIGHUP received. Attempting to restart
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20060613/php_gd.so’ – (null) in Unknown on line 0
% Digest: generating secret for digest authentication …
% Digest: done
% Apache/2.2.6 (Unix) mod_ssl/2.2.6 OpenSSL/0.9.7l DAV/2 PHP/5.2.4 configured — resuming normal operations
% File does not exist: /Library/WebServer/Documents/favicon.ico, referer: http://localhost/phpinfo.php
What do you think the problem might be?
Clyde
Now I have GD and thanks for the great article.
However, after I have changed my php.ini, I have problems with the command line php.
php
dyld: NSLinkModule() error
dyld: Symbol not found: _php_sig_gif
Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20060613/gd.so
Expected in: flat namespace
Trace/BPT trap
Any suggestions?
subscribe above: on Mac Intel Core 2 Duo (an aluminium iMac) the 64 bit specs are required to install gd library. Also, open a session as superuser “sudo su” at the beginning of the installation.
It’s a useful piece of reference!!
I m running 10.5.2. Got the stuff compiled but doesn’t seem to work.
I m running iMac Aluminum so i used the 64-bit instructions. I got these errors:
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
Any suggestion what I can do?
Thanks a lot for your help.
Bill
Hi there
I followed your instructions and everything seemed OK till I got to this
checking for fabsf… yes
checking for floorf… yes
configure: error: libjpeg.(a|so) not found.
I get this after the below command
./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
Any ideas?
Unbe-F-ing-leavable
I had no clue what I was doing but I trusted your code, and it worked perfectly… all that I had to change was that for a few lines that were to be written in xterm, I got permission denied
So I just ran them with the word sudo before the command and it worked unbelievably!!!
I owe you a beer when you’re in San Diego! Email me if you ever are!!!
Thanks
Chad
I had idea that my Macbook is a 64bit machine until I encounter an issue while trying to follow your instruction..
GD works on my machine now! Thanks!
Absolutely fantastic. Nice explanation and perfect execution. Good work. Thanks.
Thanks for the tip — everything worked as suggested.
Very good instructions. Worked without any issues at all. Thank You!
This great tutorial works like a charm – thank you very much
If you have trouble loading GD module and extension_dir is already fixed, please pay attention in the cpu architecture part (32bit/64bit) 32-bit PHP modules doesn’t work into a 64-bit subsystem.
To have root access (with blank Admin password) you can change it temporarily from System Preferences to make “sudo bash” work in terminal, in this way we can execute all commands mentioned in this tutorial more easily.
Cheers!
Martin
From make test:
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20060613/gd.so’ – (null) in Unknown on line 0
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
So, I had been following this tutorial since the release of Leopard and continuously ran into the problem Hans mentions above:
dyld: NSLinkModule() error
dyld: Symbol not found: _php_sig_gif
I am on the last revision of the MacBook, so I used the 64-bit instructions. Unfortunately, like many others here, I always assumed it was a 32-bit machine in the past.
Cleaning up your stuff is done with:
- make clean
- phpize –clean
However, how odd it may seem, it all started working when I actually did all of this in the /SourceCache/ directory. Previously I deviated from this and tried to work from /usr/src/
If you’re having problems, clean up your source directories, make sure you use the right instructions (check Wikipedia) and do this from the /SourceCache/ directory.
Hello Hill,
Unfortunately, I seem to be failing at the first step. I’ve downloaded the necessary tar files, but the following directory doesn’t exist:
/usr/share/libtool/
And despite having X11 installed, ‘make’ and ‘gcc’ don’t seem to exist on my machine. I’m a bit puzzled by this.
Any suggestions?
An update… I’ve successfully gone through all of the steps, but GD still doesn’t appear. I seem to be following in Chris’ shoes.
One interesting bit I noticed, setting my httpd.conf to “LoadModule php5_module local/php5/libphp5.so” (or “LoadModule php5_module /usr/local/php5/libphp5.so”) causes PHP to no longer work via Apache. I verified that libphp5.so is in that directory, so I’d appreciate any feedback on this (or with getting GD installed in general – the package from entropy.ch didn’t do the trick for me).
Thanks,
-ilija
Thanks for the post. Works like a charm.
Hi Hill,
thank you and Alex very much for this great tutorial. It works on first trial with a 10.5 Server system. I only have to restart the complete server after finishing the installation. Not only the apache.
As I said : thank you guys !
matz
Thanks for posting this, Hill. GD’s installed just fine (using PHP 5.2.5 that came with the Apple 2008-002 Security Update).
I got stumped a couple of times, though, so I’ll post this here to help anyone else for future references:
1. If the directory “/usr/share/libtool/” does not exist, you need to install Xcode Tools located from “Leopard DVD/Optional Installs/Xcode Tools/XcodeTools.mpkg”
2. Make sure you have the X11 SDK installed from “Leopard DVD/Optional Installs/Xcode Tools/Packages/X11SDK.pkg”
3. If you get permission denied errors when doing a “make install”, enter “sudo make install” instead and enter your password.
I followed the instructions (using 64 bit…I have a new Macbook Pro). It works with Apache, but the command line still fails with the missing symbol errors.
Then I noticed jpeg6b wasn’t building shared libraries.
No matter what I did, I could not get jpeg6b to build shared libs this way. It only would build static.
I ended up pulling down the Macports package. I used the various patch files in the jpeg library (I applied them to the jpeg6b source with patch -p0), and that got the thing to build…(using the 64-bit config above).
Everything went together, and then it _still_ doesn’t work (missing symbol _php_sig_gif).
Any ideas?
Ah. 10.5 software update bumped PHP to 5.2.5 (not 5.2.4)…I downloaded to newer source, and still no luck.
My guess is that Apple has this patched in some weird way…
First of all thank you for your tutorial and your help.
This is what I have done:
I’ve followed your html tutorial, Alex’s tutorial, and even your txt file (unfortunately this is only for 32bits) but without any success.
Everything is installed fine, without not error, using your php.ini but the error_log still says
“HP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/gd.so’ – (null) in Unknown on line 0″
I checked the /usr/local/php5/lib/php/ dir and there is not any extensions directory over there.
could you please create another txt file for 64bits? I have noticed that you download and install more file over there and I wonder if this is the problem. It would be great also if you can explain how to clean all this mess and start with a new/clean installation.
Thanks in advance.
Sorry if this is a little long but I’m trying to help solve the
dyld: NSLinkModule() error
problem.
It sounds like this is a problem is shared by a few of us. My environment is: 10.5.2 (not server) 64 bit, php 5.2.5, apache 2.2.8.
After following the walkthrough, php in apache was indeed loaded with the gd library.
Hooray!
However, if I run php from the command line, I get:
——————————
dyld: NSLinkModule() error
dyld: Symbol not found: _php_sig_gif
Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20060613/gd.so
Expected in: dynamic lookup
Trace/BPT trap
——————————
Following the lead of Jeroen Mulder, I did every thing clean from /SourceCache/ — Previously, I too, had compiled from a different directory.
(I cleaned the source directories by simply untarring the sources again)
Unfortunately, nothing seems to have changed.
Anybody have any words of advice?
Is there somehow a difference between server and standard(?) 10.5?
Anything I can do to help somebody help me/us?
A short term workaround for the problem:
dyld: NSLinkModule() error
I copied my /etc/php.ini to a file called /etc/php.nogd.ini
I then reversed the php changes suggested by the walkthrough (reversed them in the _new_ php.nogd.ini).
————————–
; commented out the line:
; extension=gd.so
; put the following line back in:
extension_dir = “./”
————————–
After doing that you can sort of get your old command line php back?
By example, this should work now (should work without the new php.nogd.ini too):
php –no-php-ini –version
More importantly, this should now work:
php –php-ini /etc/php.nogd.ini yourscriptname.php
Obviously no gd support is there for the command line, but apache will have it.
Aside from this fugly workaround, I’d still be thankful for other advice.
The problem is that you’re supposed to compile php and gd together. So not all symbols are resolved.
mod_php5 contains those symbols, the php on the command line doesn’t
You need to fully recompile php doing the follow:
MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp ” CCFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch i386 -arch x86_64 -bind_at_load” ./configure –prefix=/usr –mandir=/usr/share/man –infodir=/usr/share/info –disable-dependency-tracking –with-apxs2=/usr/sbin/apxs –with-ldap=/usr –with-kerberos=/usr –enable-cli –with-zlib-dir=/usr –enable-trans-sid –with-xml –enable-exif –enable-ftp –enable-mbstring –enable-mbregex –enable-dbx –enable-sockets –with-iodbc=/usr –with-curl=/usr –with-config-file-path=/etc –sysconfdir=/etc –with-openssl –with-xmlrpc –with-xsl=/usr –without-pear –with-gd
make
sudo make install
Note that I do not compile for ppc nor ppc64, don’t need them, you may.
No more error on the command line.
For those requiring mysql compile mysql first using:
MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp ” CCFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch i386 -arch x86_64 -bind_at_load” ./configure –prefix=/usr/local/mysql –with-unix-socket-path=/usr/local/mysql/run/mysql_socket –with-mysqld-user=mysql –with-comment –with-debug
make
make install
then compile php 5.2.5 again with:
MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp ” CCFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch i386 -arch x86_64 -bind_at_load” ./configure –prefix=/usr –mandir=/usr/share/man –infodir=/usr/share/info –disable-dependency-tracking –with-apxs2=/usr/sbin/apxs –with-ldap=/usr –with-kerberos=/usr –enable-cli –with-zlib-dir=/usr –enable-trans-sid –with-xml –enable-exif –enable-ftp –enable-mbstring –enable-mbregex –enable-dbx –enable-sockets –with-iodbc=/usr –with-curl=/usr –with-config-file-path=/etc –sysconfdir=/etc –with-mysql-sock=/var/mysql –with-mysqli=/usr/bin/mysql_config –with-mysql=/usr/local/mysql –with-openssl –with-xmlrpc –with-xsl=/usr –without-pear –with-gd
I followed your directions, but it seems that the disabling of:
extension_dir = “./”
seems to have disabled all my other extensions like support for MySQL.
Any idea how to fix that?
Actually, now that I understand the php CLI does not have the image symbols, I realize that the apache plugin _is_ working.
The dual configurations (using php -c altphp.ini) is an acceptable solution in my env (I run regression tests with the CLI, so I don’t really need GD there).
Thanks!
I followed this guide, and it all seemed to work. But when I restarted apache I got: “PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20060613/gd.so’ – (null) in Unknown on line 0″. I checked the folder /usr/lib/php/extensions/no-debug-non-zts-20060613/ and found a gd.so that was not empty. Any ideas?
Great article and Great instructions. Thank you
A simpler solution to the CLI issue is make a php-cli.ini file with GD disabled and your command line PHP should work as expected. No recompile and Apache’s version of PHP has GD working.
CLI and php.ini extension errors: an easy solution that does not require a php.ini file with disabled extensions is to invoke
php -n
the -n option skips the php.ini file and works for example with bake.php of the cakephp framework.
sudo -s gives you a root terminal session until you type exit or quit. the step to enable root user is not necessary.