Installing GD Libraries for Leopard Apache PHP 5.2.5

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
gd

33 comments to Installing GD Libraries for Leopard Apache PHP 5.2.5

  • ade

    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)

  • Tim

    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

  • Thomas Jörg

    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.

  • Sergey

    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

  • Tim

    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…

  • scops

    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 :)

  • scops

    here is my code to test (just a testing code):

  • scops

    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);

  • Tim

    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().

  • Tim

    I think the reason is posted here:
    http://developer.apple.com/releasenotes/CoreFoundation/CoreFoundation.html

    CoreFoundation and fork()

    Due to the behavior of fork(), CoreFoundation cannot be used on the child-side of fork(). If you fork(), you must follow that with an exec*() call of some sort, and you should not use CoreFoundation APIs within the child, before the exec*(). The applies to all higher-level APIs which use CoreFoundation, and since you cannot know what those higher-level APIs are doing, and whether they are using CoreFoundation APIs, you should not use any higher-level APIs either. This includes use of the daemon() function.

    Additionally, per POSIX, only async-cancel-safe functions are safe to use on the child side of fork(), so even use of lower-level libSystem/BSD/UNIX APIs should be kept to a minimum, and ideally to only async-cancel-safe functions.

    This has always been true, and there have been notes made of this on various Cocoa developer mailling lists in the past. But CoreFoundation is taking some stronger measures now to “enforce” this limitation, so we thought it would be worthwhile to add a release note to call this out as well. A message is written to stderr when something uses API which is definitely known not to be safe in CoreFoundation after fork(). If file descriptor 2 has been closed, however, you will get no message or notice, which is too bad. We tried to make processes terminate in a very recognizable way, and did for a while and that was very handy, but backwards binary compatibility prevented us from doing so.

  • Tim

    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 =)

    Finally, there’s a big problem with FreeType. As I discovered, anytime FreeType fonts are used by GD, they apparently make a Carbon API call of some sort. Problem is, Apache2 uses fork() without a corresponding exec() and, upon calling PHP/GD/FreeType, the Carbon call in FreeType causes Apache2 to crash.

  • scops

    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

  • Tim

    @Brady, did you download the required GD extensions in step 2 of the instructions?

    Regards,
    Tim

  • Noz

    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.

  • Noz

    Update: I went to the topicdesk site (missed it the first time) and used the 64bit configure string. Seems to work now. Cheers.

  • daniel

    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

  • Matt

    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/

  • Ryan

    This worked like a charm. Thank you!!

  • Ferrai

    Hi,

    Recompiling GD with Freetype 2.3.5 worked brilliantly.

    Thanks so much!

  • docmike

    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.

  • Chris

    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

  • nobody

    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.

  • Tom Løkka

    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

  • Tom Løkka

    Hi again.

    I am using 10.5.6 on a PPC 2×1,8 mhz G5.

    Kind Regards
    Tom Løkka
    Norway

  • Tom Løkka

    I also have php5, mySQL and Apache running just fine before trying this.

    Kind Regards
    Tom Løkka
    Norway

  • Tom Løkka

    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.

  • Tom Løkka

    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.

  • Tom Løkka

    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

  • Beni Stewart

    I got GD installed just fine but still need T1Lib. How do I install it after installing GD?

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">