mardi 30 novembre 2010

compiling php extension under Mac OS X 10.5

Today, I installed the amazing Xdebug PHP extension and had some troubles making it running under my Apache2 installation. This short blog post is intended to keep track of the issue and might help other people encountering a similar issue.


Firstly, the symptoms : xdebug loads correctly under CLI (ie PHP launched from shell) since it shows the "with Xdebug v2.1.0". Under apache2, it reports a cryptic error:
Failed loading /usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so:  (null)
On for a debugging session!

Firsty, my computer run Mac OS X 10.5.8 updated as of 11/30/2010 and I rely on Apple tools to develop PHP scripts. This mean:
  • PHP 5.2.14 (built: Oct  6 2010 16:57:10) 
  • Apache 2.2.14
  • phpize --version reports:
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
I compiled Xdebug using the usual steps:
  • wget
  • tar -xvzf
  • cd xdebug2.1
  • /usr/bin/phpize
  • ./configure && make
  • sudo cp ./modules/xdebug.so ...
  • sudo apachectl restart

After some googling, I found the solution in a blog post by Patrick Gibson. Here is the lame copy pasting :

MACOSX_DEPLOYMENT_TARGET=10.5 \
CFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
LDFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
CXXFLAGS='-arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' \
./configure --enable-xdebug
The above environment variables are used to instruct configure and make that a multiple architecture library should be build. I then did the usual make, copy and Apache restart. Et Voilà! Problem fixed.

I am not sure what is the real cause of the issue, probably related to the Apache2 libphp5.so.

Last step was to report the issue:

I have contacted Xdebug author Derick on irc, since this issue can probably get handle by tweaking the configure script. After a quick bug report, it is an issue with Mac OS X phpize which does not include the MACOSX_DEPLOYMEN_TARGET environment variable nor the CFLAGS, LDFLAGSn CXXFLAGS needed to build a multi architecture library. Basically not an issue with Xdebug itself.

Hence this blog post to make sure I remember the above compilation FLAGS.