Setup Xdebug on OS X Leopard

Note: If you’re using Leopard, the directions below are for you. If you’re using Snow Leopard, just follow the directions provided at xdebug.org.

Most of the blog posts I’ve seen about getting Xdebug working on OS X insist that you must use MAMP or XAMPP to do so. But since PHP and Apache come included with OS X, it seems like overkill to use one of those packages.

Contrary to popular belief, it is possible to get Xdebug working with the OS X standard Apache/PHP installation. Here’s how I did it:

  1. Download Xdebug source
  2. Extract the xdebug tarball
  3. cd into the xdebug directory
  4. Run: phpize
  5. Run: MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load” ./configure –enable-xdebug
  6. Run: make
  7. cp modules/xdebug.so /usr/lib/php/extensions/no-debug-non-zts-20060613 (note: your path may be slightly different)
  8. add the following line to php.ini: zend_extension=”/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so”
  9. Run: sudo apachectl restart
  10. Write a PHP page that calls “phpinfo();” Load it in a browser and look for the info on the xdebug module. If you see it, you have been successful!

This is simply a modified version of the README file that comes with the xdebug source. The most important tweak is step 5, which sets the correct flags for the resulting module to work with Apache as it is compiled in OS X.

Note: If you’re currently using another debugger, you will need to disable it before Xdebug will work.