Building PHP in Mac OS 10.5.3

Posted on June 8th, 2008 | No Comments »

Just like every other Mac user out there, I installed 10.5.3 when it dropped last week. And, like so many times before this, the os x update broke my local build of PHP. This time, after rebuilding PHP & Apache, I was still unable to start apache, being told that libphp5.so was the wrong architecture.

This time apparently php was building as i386, but httpd was running as x86_64 (I’ve got a SR MacBook pro as my build environment, your mileage may vary.) So, instead of figuring out how to cajole php into building as x86_64, I fell back on my friend lipo to make sure httpd was running i386. Here’s what I did:

sudo apachectl stop
cd /usr/sbin
sudo mv httpd httpd_old
sudo lipo -thin i386 httpd_old -output httpd
sudo rm -f httpd_old
sudo apachectl start

This looks like it solved all of my problems. I might keep this in mind for when 10.5.4 drops, to make my life a good bit easier.

In the mean time, if you can tell me how to convince php to build x86_64, I won’t mind. ./configure detects the following about my system:

checking host system type... i686-apple-darwin9.3.0
checking target system type... i686-apple-darwin9.3.0

Maybe i’m destined to run as i386, which I don’t mind, so long as it runs.

Cheers!

iPhone SDK makes building PHP tricky

Posted on March 25th, 2008 | No Comments »

This morning, I needed to rebuild PHP.  I haven’t done it in months, but was sure it would be painless.  I hadn’t counted on, however, that I’d installed the iPhone SDK at the beginning of this month.  The iPhone SDK is Xcode 3.1, which I believe is beta (might not be, no real research.)  I think that it also installs gcc 4.2.  I forgot both of these facts before I tried to configure my php build.  Upon my inital pass, I was greeted with the following error:

configure: warning: –with-zlib: invalid host type
configure: warning: –with-mysql=/usr/local/mysql: invalid host type
configure: error: can only configure for one host and one target at a time

I, of course, didn’t bother to properly troubleshoot the error, as I didn’t really have time to track down a solution.  I did, however, manage to get a build in place.  I removed the current install of my developer tools, ala:

sudo /Developer/Library/uninstall-devtools --mode=all

And then I proceeded to reinstall the tools on my Leopard DVD.  I restarted for good measure, and was off to the races.  Have any of you encountered this issue?

Building PHP in Leopard

Posted on December 11th, 2007 | 2 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.