Another post for my fading memory, how to install the GD libraries for your Leopard Apache installation running PHP 5.2.5. I will be using these libraries in a forthcoming blog about the use of ‘sparklines‘ to present complex performance monitoring data.
Now on with installation. Thanks to topicdesk for leading the way with detailed OSX 10.5.x server installation instructions. Here’s my own shorthand version …
Note: You will first need to install the Apple Developer Tools that come with your OSX installation DVD!
1. Download, compile and install a copy of libjpeg in your ~/Downloads directory
cd ~/Downloads/jpeg-6b
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
./configure --enable-shared
sudo make
sudo mkdir -p /usr/local/include
sudo mkdir -p /usr/local/bin
sudo mkdir -p /usr/local/lib
sudo mkdir -p /usr/local/man/man1
sudo make install
2. Download, compile and install a copy of PHP GD extensions in your ~/Downloads directory
cd ~/Downloads/php-5.2.4/ext/gd/
sudo phpize
sudo ./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
sudo make
sudo make install
3. Modify your php.ini
sudo cp /etc/php.ini.default /etc/php.ini
sudo vi /etc/php.ini
add the following line to your extensions
extension=gd.so
comment the following line for your extensions dir with a ';'
extension_dir = "./"
save and quit vi (:wq!)
4. Restart Apache and check the results using phpinfo()
sudo apachectl restart


Is this only possible with OS X server?
I have PHP 5.2.5 running on OS X 10.5.2 (the standard desktop version), but I do not have this directory:
/usr/share/libtool/
…so cannot complete step 1.
(and yes, I have turned on show hidden files)
Yes it is possible, I am also using OSX 10.5.2 (on my macbook pro).
You will first need to install the Apple Developer Tools that come with your OSX installation DVD. I have amended the instructions above to suit.
Regards,
Tim Koopmans
hello sounds great. everything worked fine. phpinfo claims that freetype is enabled. but freetype can not be used with ttf fonts. can you use freetype on your machine???
we are running a dual g4 xserve.
Hello, this may be endianess (byte order) issues.
PowerPC is big-endian , Intel is little-endian.
Don’t get me wrong, I don’t know if TTF files is endian-related.
Maybe it is, maybe is not
We also had same problem with bitmap font used
with a barcode generator, it must be re-ordered for G4
Do you have a test case I can try out on my Intel machine? I am only using this library for the drawing capabilities, not rendering of fonts. Perhaps if u can provide a demo php file and I will try it out…
i have the same problem with ttf fonts… can someone help? this says the log file:
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.
i need to use ttf fonts… :/ besides that. this howto is really great. worked fine on my leopard ibook g4
here is my code to test (just a testing code):
function fixbbox($bbox){
$xcorr=0-$bbox[6]; //northwest X
$ycorr=0-$bbox[7]; //northwest Y
$tmp_bbox['left']=$bbox[6]+$xcorr;
$tmp_bbox['top']=$bbox[7]+$ycorr;
$tmp_bbox['width']=$bbox[2]+$xcorr;
$tmp_bbox['height']=$bbox[3]+$ycorr;
return $tmp_bbox;
}
$text_obj_size = fixbbox(imagettfbbox(14, 0, "lcars.ttf", "seid gegrust"));
$im = imagecreatetruecolor($text_obj_size['width'],$text_obj_size['height']);
$black = ImageColorAllocate ($im, 0, 0, 0);
$white = ImageColorAllocate ($im, 255, 255, 255);
imagettftext($im, 14, 0, $text_obj_size['left'], $text_obj_size['top'], $white, "lcars.ttf", "seid gegrust");
imagejpeg($im);
Just confirming that I am also getting the same error above when using the test code provided on a Macbookpro intel.
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
I think the reason is posted here:
http://developer.apple.com/releasenotes/CoreFoundation/CoreFoundation.html
If you check this thread
http://discussions.apple.com/thread.jspa?messageID=5693097
, there is some discussion about the root cause of this. Hopefully that can sort you out =)
Ok i’ve got it! thanks Tim for the threatlinks!
This is what i have done:
before compile of GD just
“Get FT2 and expand the tarball:
(in Sources–my version of /SourceCache):
curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz
cd ..
tar xvfp Sources/freetype-2.3.5.tar.gz
Configure FT2 and make it:
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-fsspec=no –with-fsref=no –with-quickdraw-toolbox=no –with-quickdraw-carbon=no
make
sudo make install” (thanks to a comment in the threat above, build universal bin.)
and then compile gd with the new build freetype:
sudo ./configure –with-zlib-dir=/usr –with-jpeg-dir=/usr/local/lib –with-png-dir=/usr/X11R6 –with-freetype-dir=/usr/local/lib –with-xpm-dir=/usr/X11R6
I’ve given this a try under 10.5.3, PowerPC Server, and I can’t see the GD Library anywhere! Any advice is appreciated, seems like the system is fine regardless. Thank you
@Brady, did you download the required GD extensions in step 2 of the instructions?
Regards,
Tim
I’m running 10.5.3 PPC Desktop, and I’m having the same trouble as Brady. gd.so definitely compiled, but it wasn’t transferred to a logical place. It was still in the build folder. I’m not exactly sure where the gd.so file should be located, but it’s definitely not being found by php.
Update: I went to the topicdesk site (missed it the first time) and used the 64bit configure string. Seems to work now. Cheers.
I have problems with truetype fonts. How can I solve it?
Thanks!
I have followed the steps described above – all worked fine, until I got to the last sudo make, which resulted in this message:
powerpc-apple-darwin9-gcc-4.0.1: /usr/X11/lib/libpng12.0.26.0.dylib: No such file or directory
make: *** [gd.la] Error 1
daniel,
your issue is that the libtool file for libpng is incorrect.
Open /usr/X11/lib/libpng.la (or whatever it is on your system) and change the line that says libpng12.0.26.0.dylib to the correct filename in /usr/X11/lib/
This worked like a charm. Thank you!!
Hi,
Recompiling GD with Freetype 2.3.5 worked brilliantly.
Thanks so much!
On OS X 10.5.4 (non-server), I also got the libpng12.0.26.0.dylib not found error, and editing libpng12.la as prescribed didn’t help. But I then noticed from the make output that the last gcc invocation referenced libpng12.0.26.0.dylib directly, so I created a symlink called libpng12.0.26.0.dylib pointing to the same file that libpng12.0.24.0.dylib points to. GD then built just fine.
running the above configure command returned this error:
sh: ppc: command not found
does anyone know where I can download this or is this an error due to some other issue?
Hi,
thanks for the tutorial; I must be missing something and any help would be appreciated.
I followed the steps and everything worked without any errors. But…
phpinfo() tells me that my extension dir is now /usr/lib/php/extensions/no-debug-non-zts-20060613
When I look in that directory, gd.so does exist in there.
So far so good, but phpinfo() does not say anything about gd and gd does not seem to be installed.
I double-checked everything, restarted my computer, made sure my php.ini file is OK, and basically I am at a loss as to what to do now…
Again, thanks for sharing the knowledge! Cheers,
Albert.
Hi,
me again. Found the solution to my problem: turns out I have a macbook core duo, which is a 64-BIT MACHINE.
This tutorial works fine on 32-bit machines, but on my machine resulted in “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″ being writtent to the apache error log.
So the solution is documented in http://www.veola.net/macintosh/adding-gd-library-for-mac-os-x-leopard and works fine. Just start over, and make sure you Make clean before all your make commands, just to get rid of old 32-bit stuff.
Also, redoing the process resulted in some “permission denied” errors in ./configure. I just chmoded all recalcitrant files to 777.
I now have GD on my mac! Thanks to all for your great work.
Albert
You’re using sudo too much. Only use it when you need escalated privileges, not before every single shell command you type. The more you use it, the more chance you have of accidentally raping your system.
Hi.
When I run: “./configure –enable-shared”, I got at the end: “checking host system type… ltconfig: cannot guess host type; you must specify one
Try `ltconfig –help’ for more information.
checking libjpeg version number… 62
creating ./config.status
creating Makefile
creating jconfig.h”.
Is that something to worry about?
Then when I type “sudo make”, I got this error: “sh-3.2# sudo make
./libtool –mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool: Command not found
make: *** [jcapimin.lo] Error 127″.
What can I do about it?
Kind Regards
Tom Løkka
Norway
Hi again.
I am using 10.5.6 on a PPC 2×1,8 mhz G5.
Kind Regards
Tom Løkka
Norway
I also have php5, mySQL and Apache running just fine before trying this.
Kind Regards
Tom Løkka
Norway
I now fixed the problem I first got, but after “make” and “make install” where it said “Build complete”, I did “make test”, and the I got a PHP Warning “PHP Warning: Module ‘gd’ already loaded in Unknown on line 0″ and a long list of “FAIL” and “Bug”, and my GD is not working.
I dont now what is wrong.
I got some more info. When I try this:
sh-3.2# php -r “phpinfo();” |grep GD
GD Support => enabled
GD Version => bundled (2.0.34 compatible)
sh-3.2#
, it says that GD is enabled, (but still not working) and I cant see it in my phpinfo file.
Hi again.
The problem is solved. The problem was that in this guide, it is for 32bit Mac, not 64bit like my G5. I followed the guide from this Site:
http://www.veola.net/macintosh/adding-gd-library-for-mac-os-x-leopard
Here you find commands for both 32bit and 64bit and I used 64bit.
Kind Regards
Tom Løkka
I got GD installed just fine but still need T1Lib. How do I install it after installing GD?