jQuery Lightbox, now at Google Code Happy New Year!

Building PHP in Leopard

Posted in: Development, PHP, os x Add comments

Like many of you, i’m sure, I was impressed with Apple’s inclusion of PHP 5 in Leopard.  For nearly 2 months,  i’ve been using the default PHP install without a single complaint.  It worked just fine,  had mysql support,  and worked with mostly everything i’d been working on.  Eventually, however, I needed more out of php than the base install allowed for. I needed the SOAP extension, I needed OpenSSL support, I needed mcrypt,  I wanted JSON,  I wanted GD.  (Actually, I needed those things for work, minus GD.)

Initally,  I simply downloaded PHP 5.2.5 from php.net and started to build.  I found out that some of the libraries I wanted to include weren’t included in OS X,  so I had to install them first.

Leopard includes XML libraries, so the SOAP extension works out of the box.  OpenSSL also works out of the box.  Mcrypt was the first extension that needed to be built.  It worked like this:

Download libmcrypt

cd <libmcrypt dir>
./configure --disable-posix-threads
make
sudo make install

Now you’ve got libmcrypt installed,  the next extension that needs anything installed is GD.  I won’t bother telling you how to install GD. I just used libpng, because PNG’s are what I work with.

That wraps up what I needed before I could build PHP.  It was time to download the PHP 5.2.5 source, and get rolling.  Here was how I configured PHP:

./configure --with-zlib --with-mysql=/usr/local/mysql --with-apxs2=/usr/sbin/apxs --enable-soap --with-openssl --with-mcrypt --with-gd
make
sudo make install

At this point,  your install will complain about apxs.  I attempted to restart apache,  but I had no success.  Calling :  apachectl -t  gave me a warning about libphp5.so no loading properly, due to the wrong architecture.  file libphp5.so reported that I had the right arch, so I was stumped.  I was left with apache 2 not being able to load my php module.

I tried a bunch of different things to fix the problem, but eventually solved it simply by rebuilding apache.  Just download httpd 2.2.3 (current as of this writing),  configure as you’d like (a simple ./configure will work without any options), make, sudo make install,  and then restart apache.

Voila,  you’re running the latest & greatest PHP and Apache on the latest & greatest Mac OS.

2 Responses to “Building PHP in Leopard”

  1. charles Says:

    The problem with apache2 is that it thinks its running as an i386 so when you do a config you can just add the option ‘-enable-layout=Darwin’ and it works out your on a mac, stops complaining about the so arch type.

  2. Quinn Taylor Says:

    I found a site that allowed me to install GD support for PHP 5 on Leopard, using Apple’s actual modified source drop, and you don’t have to touch Apache at all. I haven’t yet played with it enough to add mcrypt support, but that’s an eventual goal. You could probably add that in pretty easily.

    http://downloads.topicdesk.com/docs/Adding_GD2_to_PHP_on_OS_X_Server_10_5_Leopard.pdf

Leave a Reply