Building and Installing Xdebug on XAMPP for OS X 10.6

Content

Building and Installing Xdebug on XAMPP for OS X 10.6

Posted in:

We want to build Xdebug and install on XAMPP for OS X 10.6

So we we want to download XDebug, however we need to make sure we get the correct version. So go to http://www.xdebug.org/find-binary.php and paste in the results of running phpinfo() on your XAMPP stack.

On OS X 10.6 find-binary.php reports:

Tailored Installation Instructions

Summary

  • Xdebug installed: no
  • Server API: Apache 2.0 Handler
  • Windows: no
  • Zend Server: no
  • PHP Version: 5.2.9
  • Zend API nr: 220060519
  • PHP API nr: 20060613
  • Debug Build: no
  • Thread Safe Build: no
  • Configuration File Path: /Applications/XAMPP/xamppfiles/etc
  • Configuration File: /Applications/XAMPP/etc/php.ini
  • Extensions directory: /Applications/XAMPP/xamppfiles/lib/php/php-5.2.9/extensions/no-debug-non-zts-20060613

So we download the recommended version at http://xdebug.org/files/xdebug-2.1.0.tgz. We unpack, read the README and fire off phpize. What it reports is:


Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626

Now this is not what we expect. Our required PHP API ref is 20060613, not 20090626. Looking at the man entry for phpize it says:

This manpage describes php, version 5.3.1.

So we realise that the OS X installed php version is 5.3.1 while our XAMPP version is still at 5.2.9. No problem, there exists a certain /Applications/XAMPP/xamppfiles/bin/phpize so we utilise it, only to be informed that the necessary includes are missing. Looking at XAMPP we see that we are running 1.0.1, which is a bit behind the times, but we don't want a reinstallation just at this moment (we are targeting Drupal 6 which is not wholly relaxed with php 5.3).

So it's off to http://sourceforge.net/projects/xampp/ where we locate the developer dmg download for XAMPP 1.0.1. This installs without much fanfare but when it's done the necessary include files are present in the XAMPP hierarchy. Now we run XAMPP's phpize and see:

PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

So at least we are on the right track now. So we configure and build a copy the shared object to the extensions folder:

sudo cp modules/xdebug.so /Applications/XAMPP/xamppfiles/lib/php/php-5.2.9/extensions/no-debug-non-zts-20060613

Then it's a matter of updating XAMPP's php.ini as follows

[xdebug]
zend_extension="/Applications/XAMPP/xamppfiles/lib/php/php-5.2.9/extensions/no-debug-non-zts-20060613/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_port=9000
cgi.force_redirect = 0

Read this too http://community.activestate.com/forum-topic/php-xdebug-troubleshootin

We restart XAMPP and examine the output of phpinfo() in vain. No sign of our debug module.

Scanning the XAMPP log files we come across /Applications/XAMPP/xamppfiles/logs/error_log which contains entries such as:

Failed loading /Applications/XAMPP/xamppfiles/lib/php/php-5.2.9/extensions/no-debug-non-zts-20060613/xdebug.so: (null)

So at least we have a file in the right place. We have built our debug.so but what exactly have we built. Using otool we see:

otool -hv xdebug.so
xdebug.so:
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC_64 X86_64 ALL 0x00 BUNDLE 8 1408 DYLDLINK

This is not encouraging as httpd on XAMPP 1.0.1 is 32 bit. We check one of the other shared objects in /Applications/XAMPP/xamppfiles/lib/php/php-5.2.9/extensions/no-debug-non-zts-20060613 to be sure:

otool -hv sqlite.so
sqlite.so (architecture i386):
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC I386 ALL 0x00 BUNDLE 8 1248 DYLDLINK SUBSECTIONS_VIA_SYMBOLS
sqlite.so (architecture ppc):
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC PPC ALL 0x00 BUNDLE 7 1192 DYLDLINK

So we quickly modify the Xdebug makefile to include -m32 for CFLAGS and LDFLAGS. A rebuild confirms that we now have a 32 bit so file. We copy it to the extensions folder and restart XAMPP.

Again, Xdebug is still conspicuous by its absence. We return to /Applications/XAMPP/xamppfiles/logs/error_log to discover:

Xdebug requires Zend Engine API version 220090626.
The Zend Engine API version 220060519 which is installed, is outdated.

So at least we may presume that we have the architecture correct now!

The problem is that even though we used the correct XAMPP version of phpize initially during the build the OS X installed version of php is referenced, which is where the Zend API version of 220090626 comes from. Looking at configure.in it's clear that php-config is queried to determine the path to the php binary. The solution here is simply to prefix the shell $PATH with the path to our XMAPP bin folder so that it is searched before /usr/bin.

export $PATH='/Applications/XAMPP/xamppfiles/bin':$PATH

We reconfigure the build, making sure that we still have our 32 bit options, and rebuild.

When the resulting xdebug.so is copied to our extensions folder phpinfo() this time reveals the presence of debug.

See also http://blog.visionsource.org/2010/05/31/installing-php-extensions-on-mac... for a more sensible approach to getting configure to build what we require.

The path of least resistance is probably to install the most recent version of XAMPP as the php version will more likely match that of OS X, which makes building the extension less fraught.

OS X users should check out MacGDBp. This provides a lightweight alternative to Eclipse hosted PHP debugging.