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

Post a Comment

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