Compiling php with GD support

Summary: compiling php with GD support on Tiger 10.4.7 (so we can do cool stuff with Garland)
Geekiness: 5 / 5

Technorati Tags: , , , ,



Garland and the Drupal colour module

Drupal 5 has this cool new theme called Garland which uses the colour module allowing complete site colour changes on the fly. The only trick is that php needs to be compiled with GD support. Since I’m wanting to play with Garland on my mac, let’s figure out how to get it all working.

I’m assuming you’ve already edited that line in httpd.conf so as to uncomment out the php module. Restarting apache (sudo apachectl restart) gives you working web-based php scripts. Next, open terminal and type php -i to get some info about your php environment. The first line will give you the php version – mine is 4.4.1. It will also give you all sorts of interesting information.

Building and installing libraries

Pay attention to the line beginning “Configure Command” – it shows what php was last compiled with. What we’re going to do is modify that line by simply adding the necessaries to get GD working. There are some pre-requisites: the libjpeg, libpng (requiring zlib) and libtiff libraries. You can set them up this manually or use the fantastic Fink Commander (which lets you at a whole bunch of unix apps). If you haven’t used Fink before, it just sets up a /sw top level directory (here’s how) and throws all source and binaries in there. So if you want to install Apache 2 or wget (wow, I love wget!) grab Fink. You’ll also need the Apple Developer Tools installed (they come with your original OS X cds – just install from there) so you can build from source.

Check through the php -i | grep zlib output and see if zlib is already set up on your system. If it’s not, then install it. That’s a bit more work since Fink doesn’t do it for you. Not a problem – grab the source then run a “make” and a “make install”. It should be put nicely in /usr/local. Now we’re ready to tackle recompiling php.

Fetching and building php

Grab the latest php version and unpack it on your desktop. I’m going to stick with the latest 4 dot release (4.4.4) – if anyone can give me a good reason why I should use version 5, let me know. Now build your “compile” command by copying the “Configure Command” line from the output of “php -i”. Remove all those silly quotes and add in the following for GD support:
–with-zlib-dir=/usr/local –with-libjpeg=/sw –with-libtiff=/sw –with-libpng=/sw –with-gd

My configure command now looks like this:
./configure \
–prefix=/usr \
–mandir=/usr/share/man \
–infodir=/usr/share/info \
–disable-dependency-tracking \
–with-apxs \
–with-ldap=/usr \
–with-kerberos=/usr \
–enable-cli \
–with-zlib-dir=/usr \
–with-png-dir=/sw \
–with-jpeg-dir=/sw \
–with-libtiff=/sw \
–with-gd \
–enable-trans-sid \
–with-xml \
–enable-exif \
–enable-ftp \
–enable-mbstring \
–enable-mbregex \
–enable-dbx \
–enable-sockets \
–with-iodbc=/usr \
–with-curl=/usr \
–with-config-file-path=/etc \
–sysconfdir=/private/etc \
–with-mysql=/usr/local/mysql \
–with-mysql-sock=/private/var/mysql/mysql.sock

So I ran the configure above and it worked ok – did a make and a make install but php wouldn’t see mysql: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2). What to do? It would seem that the configure line –with-mysql-sock=/private/var/mysql/mysql.sock didn’t take so we have to fix that. According to Apple there are 2 options: change the location where MySQL creates its socket file or change the location where PHP looks for the socket file. I chose the latter.

To do this, edit your php.ini file, search for the line mysql.default_socket = and change it to
mysql.default_socket = /var/mysql/mysql.sock Restart apache and…Whohoo!

Comments

  1. February 16th, 2007 | 1:08 pm

    Damn that’s geeky. Reminds me of my early linux days spending days to get peripherals working :) (and what a sense of accomplishment)

    Usually I’m an entropy fighter and when it comes to mac I dig giving in to the entropy, specifically the PHP Apache modules all packaged and ready to run :)

    http://www.entropy.ch/software/macosx/php/
    The module includes support for lots of extensions, among them the ones listed below:

    the MySQL and PostgreSQL databases
    the PDFLib PDF library
    the cURL library for various communications protocols
    the GD image creation library (with PNG, JPEG, PostScript Type 1 and TrueType font options).
    ET AL

Leave a reply