Enabling GD library for PHP 4.4.4 on Mac OS X

Posted on December 16, 2006 on 2:21 am by glen | In MySQL, PHP, Apache, Mac |

For some reason, GD is not enabled in the default Mac OS X build of PHP 4.4.4. Here’s an easy way to install. Make sure you have the following fink packages installed:

  • libpng3
  • libjpeg

1. Download the source code for PHP 4.4.4

PHP 4.4.4 source

2. Unpack the source

tar jxvf php-4.4.4.tar.bz2
cd php-4.4.4

3. Compile and install the GD extension


cd ext/gd
phpize
./configure --with-jpeg-dir=/sw --with-png-dir=/sw --with-zlib-dir=/usr
make
sudo make install

This last stage will install the GD shared object into /usr/lib/php/extensions/no-debug-non-zts-20020429/

4. Pull in the GD module at startup

Edit /etc/php.ini and add the following line:

; Enable gd extension module
extension=gd.so

and make sure the following line is commented out:

;extension_dir = "./"

5. Restart Apache

sudo apachectl graceful

Bingo!

GD info

4 Comments »

RSS feed for comments on this post. TrackBack URI

  1. I used your guide to enable gd lib on my mac webserver, but I have problems with the PHP CLI. It produces the following output:
    mac: user# php -v
    dyld: NSLinkModule() error
    dyld: Symbol not found: _php_sig_gif
    Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20020429/gd.so
    Expected in: flat namespace

    Trace/BPT trap

    Any ideas how I could make this workable?

    Comment by Benni — 4th January, 2007 #

  2. Unfortunately, there seems to be a problem with the CLI version of PHP included with OS X. It doesn’t seem to be able to load extensions dynamically. I can’t see any way around this at the moment :(

    Comment by glen — 4th January, 2007 #

  3. So I get to step 3 and get stuck any ideas?

    WebEmailServer:~/Desktop/php-4.4.4/ext/gd rwsccadmin$ phpize
    grep: /usr/include/php/main/php.h: No such file or directory
    grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
    grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
    Configuring for:
    PHP Api Version:
    Zend Module Api No:
    Zend Extension Api No:
    cp: /Users/rwsccadmin/Desktop/php-4.4.4/ext/gd/build/libtool.m4: Permission denied
    cp: /Users/rwsccadmin/Desktop/php-4.4.4/ext/gd/build/shtool: Permission denied
    cp: /Users/rwsccadmin/Desktop/php-4.4.4/ext/gd/build/scan_makefile_in.awk: Permission denied
    cp: /Users/rwsccadmin/Desktop/php-4.4.4/ext/gd/build/mkdep.awk: Permission denied
    cp: /Users/rwsccadmin/Desktop/php-4.4.4/ext/gd/ltmain.sh: Permission denied
    cp: /Users/rwsccadmin/Desktop/php-4.4.4/ext/gd/config.guess: Permission denied
    cp: /Users/rwsccadmin/Desktop/php-4.4.4/ext/gd/config.sub: Permission denied
    cp: /Users/rwsccadmin/Desktop/php-4.4.4/ext/gd/Makefile.global: Permission denied
    cp: /Users/rwsccadmin/Desktop/php-4.4.4/ext/gd/acinclude.m4: Permission denied
    Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
    environment variable is set correctly and then rerun this script.

    WebEmailServer:~/Desktop/php-4.4.4/ext/gd rwsccadmin$ ./configure –with-jpeg-dir=/sw –with-png-dir=/sw –with-zlib-dir=/usr
    -bash: ./configure: No such file or directory

    Comment by Jesse — 1st February, 2007 #

  4. After much trial and error, I eventually discovered that you must have Xcode Tools installed, or glen’s instructions result in “no such file or directory” and “cannot find autoconf” errors. The Xcode Tools installer is on your OS X install disc(s), or can be downloaded from Apple’s site if you are an ADC member.

    You may also need to add sudo to glen’s first two commands, or you’ll get permissions denied errors (or I did anyway):
    sudo phpize ./configure –with-jpeg-dir=/sw –with-png-dir=/sw –with-zlib-dir=/usr
    sudo make
    sudo make install

    This successfully created the gd.so file in /usr/lib/php/extensions/no-debug-non-zts-20020429/ on my OS X 10.3.9 server.

    I then tried adding the line
    extension=gd.so
    to my php.ini file, but GD didn’t show as active on my php.info page after I restarted Apache. Changing the line to this, then restarting Apache, got it working:
    extension=/usr/lib/php/extensions/no-debug-non-zts-20020429/gd.so

    So I’m now successfully running GD, and my PHP scripts accessing it work fine.

    Comment by John Kirn — 16th February, 2007 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Feeds: Entries | Comments