Enabling GD library for PHP 4.4.4 on Mac OS X

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

15 Comments

  1. Benni says:

    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?

  2. glen says:

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

  3. Jesse says:

    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

  4. John Kirn says:

    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.

  5. diego says:

    Thank you so much!
    I followed your guide word by word and it works! :)

  6. James says:

    Great tutorial thanks.

    I had trouble finding a mirror for php 4.4.4. This is where I managed to find it:

    http://sunsite.bilkent.edu.tr/infosystems/phpweb/distributions/php-4.4.4.tar.gz

  7. lalit kumar says:

    Hello sir!,
    My problem is that if i run my page to upload images to my image_path folder. than it give the error
    :mkdir() [function.mkdir]: Permission denied in /home/acehost/public_html/lalit/vi-ga/admin1/includes/functions.inc.php

    what is the solution for that.
    Lalit

  8. Chris says:

    I know this might be a stupid newbie issue but thought I’d mention it to anyone else having problems. I downloaded the php source into my default “Web Downloads” folder. It turns out you can’t get rid of the misleading Autoconf error if you are trying to install the GD extension from a directory that has a space in the path. I copied it to my /users/chris folder and tried it again and it worked straight away.
    Also, it turned out I didn’t initially have a php.ini file, something else you may not realise is possible :-) Hope this helps others…

  9. [...] Since I’m not really a black belt console ninja, it took me quite a while to figure out how to install GD, and how to make it available in PHP. This step by step how-to finally helped me out. To make it work make sure: [...]

  10. mafro says:

    I suffer from the same problem as Benni here does. Is there any solution to it? Could I not “replace” OSX’s PHP CLI binary?

    Thanks for any help

  11. justin says:

    Worked great. Thanks

  12. [...] Since I’m not really a black belt console ninja, it took me quite a while to figure out how to install GD, and how to make it available in PHP. This step by step how-to finally helped me out. To make it work make sure: [...]

  13. freshlogics says:

    Thanks for this tutorial.

  14. John Kirn says:

    I tried to install the GD Libraries on a 10.4.11 Server running PHP 4.4.7 today, and ran into some problems. Eventually I learned the following…

    Although you can no longer download the PHP 4.4.7 source from php.net, it can be found if you google php-4.4.7.tar.bz2. 4.4.7 works just like 4.4.4 for compiling the GD extension.

    I made a mistake in my previous post… sudo phpize must be run first, followed by sudo ./configure –with-jpeg-dir=/sw –with-png-dir=/sw –with-zlib-dir=/usr. Glen’s instructions are correct.

    I found that with 10.4.7, the line for:
    extension_dir = “./”
    must be left as-is in the php.ini file. Don’t comment it out as Glen’s instructions state.

Leave a Reply