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
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!
5 Comments »
RSS feed for comments on this post. TrackBack URI
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 #
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 #
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 #
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 #
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.
Comment by John Kirn — 10th July, 2008 #