Installing GD Libraries for Leopard Apache PHP 5.2.5

29 April, 2008 – 8:14 pm

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
<em>add the following line to your extensions </em>
extension=gd.so
<em>comment the following line for your extensions dir with a ';'</em>
extension_dir = "./"
save and quit vi (:wq!)
 

4. Restart Apache and check the results using phpinfo()
sudo apachectl restart
gd

Share it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netscape
  • Reddit
  • Slashdot
  • Technorati
  • YahooMyWeb
  1. 32 Responses to “Installing GD Libraries for Leopard Apache PHP 5.2.5”

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

    By ade on May 1, 2008

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

    By Tim on May 1, 2008

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

    By Thomas Jörg on May 31, 2008

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

    By Sergey on Jun 12, 2008

  6. 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…

    By Tim on Jun 12, 2008

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

    By scops on Jun 13, 2008

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

    By scops on Jun 13, 2008

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

    By scops on Jun 13, 2008

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

    By Tim on Jun 14, 2008

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

    By Tim on Jun 14, 2008

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

    By Tim on Jun 14, 2008

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

    By scops on Jun 16, 2008

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

    By Brady J. Frey on Jun 25, 2008

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

    Regards,
    Tim

    By Tim on Jun 25, 2008

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

    By Noz on Jun 30, 2008

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

    By Noz on Jun 30, 2008

  18. I have problems with truetype fonts. How can I solve it?

    Thanks!

    By daniel on Jul 29, 2008

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

    By Boris on Aug 2, 2008

  20. 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/

    By Matt on Aug 22, 2008

  21. This worked like a charm. Thank you!!

    By Ryan on Oct 7, 2008

  22. Hi,

    Recompiling GD with Freetype 2.3.5 worked brilliantly.

    Thanks so much!

    By Ferrai on Oct 9, 2008

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

    By docmike on Nov 18, 2008

  24. 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?

    By Chris on Jan 21, 2009

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

    By Albert Albala on Feb 21, 2009

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

    By Albert Albala on Feb 21, 2009

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

    By nobody on Mar 20, 2009

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

    By Tom Løkka on Apr 11, 2009

  29. Hi again.

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

    Kind Regards
    Tom Løkka
    Norway

    By Tom Løkka on Apr 11, 2009

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

    Kind Regards
    Tom Løkka
    Norway

    By Tom Løkka on Apr 11, 2009

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

    By Tom Løkka on Apr 12, 2009

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

    By Tom Løkka on Apr 12, 2009

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

    By Tom Løkka on Apr 12, 2009

Post a Comment

*
To prove that you're not a bot, enter this code
Anti-Spam Image