PHP Dynamic Modules Mac OS X

My development machine is currently a MacBook Pro Core2Duo.  It also happens to use a 64bit architecture.  My previous machine was a MacBook Pro CoreDuo which was 32bit.

Compiling a simple dynamic extension for PHP became something of an issue when moving on to the newer MBP.

I was trying to install the RAR extension for PHP on my dev laptop to test a few unrelated bits and I got mired in the process of getting this damned extension to load for Apache.  My error logs, enabled just to debug this process, were filling up with:

PHP Warning:  PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20060613/rar.so’ – (null) in Unknown on line 0

Every page that describes the process had the same steps.  Get archive.  Untar,  ./configure, make, make install, make test, add extension=rar.so.  Blah blah blah.  One typical test was to run the CLI version of PHP and confirm that the dynamic extension was loading and was not causing startup errors:

php -i | grep rar

or

php -m | grep rar

Yep.  No problems.  I could even run tests like:

php -r “echo rar_open(‘myRar.rar’);”

The above would give me the internal ID for the rar object handle.  Great!  I was in business.  However, after bouncing Apache 2, my phpinfo() page failed to show RAR as a loaded extension.  The above impromtu tests confirmed that the proper modifications to php.ini and paths to my extensions_dir were correctly set.  WTF?

Doing some serious googling, I stumbled on a thread off of Marc Liyanage’s invaluable Mac OS X PHP site entropy.ch: http://www.entropy.ch/phpbb2/viewtopic.php?t=2877

MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch x86_64 -g -Os -pipe” LDFLAGS=”-arch x86_64 -bind_at_load” ./configure

To sum it up in one line, compiling a dynamic extension for PHP may default to a 32bit architecture.  This will fail when PHP as a DSO for Apache 2 is compiled against 64bit libs.

The punchline?  RAR now loads for Apache as intended and works a charm.  The CLI version complains every time I invoke it :).