I just upgraded my XAMPP to latest release and found myself trapped with no memory of how to install xdebug on a Mac with XAMPP.
0. Install Xcode and autoconf
Thanks to Cedric Talbot for commenting and pointing out that I had not noticed I had all the needed developer tools already in place from all the development I do on my Mac. According to Cedric’s experience, you’ll need to have at least Autoconf installed via MacPorts or Homebrew and that in turn will require you to install Xcode. Once you have Xcode installed, go to Xcode prefs -> Downloads pane and install ‘Xcode command line tools’ and when that is done, open terminal and enter:
sudo xcode-select -switch /Applications/Xcode.app
This will set the folder where the Xcode is installed so that all the command line tools find it. Now continue with Macports or Homebrew to install autoconf.
1. Install XAMPP Developer package
Building xdebug requires you to have php headers, so download and install corresponding developer package for XAMPP.
2. Download xdebug
Download xdebug source from here or checkout from GIT:
git clone git://github.com/derickr/xdebug.git cd xdebug
4. Configure xdebug
Recent XAMPP (mine was 1.8.3-2) are built 64bit and so the configure is rather simple:
./configure --enable-xdebug --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config
If your XAMPP is built for i386 (32-bit) architecture, you have to modify default build flags, which otherwise would build for x86_64 (64-bit):
./configure --enable-xdebug --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config CFLAGS="-arch i386 $CFLAGS" CCFLAGS="-arch i386 $CCFLAGS" CXXFLAGS="-arch i386 $CXXFLAGS" LDFLAGS="-arch i386 $LDFLAGS"
edit: configure command updated to append variables instead of prepending them (thanks Sequan).
edit2: Alternatively, as suggested by Junaid below, on a Lion you could use the following command (haven’t tried it myself), which is essentially the same, only providing architecture as direct argument to compiler instead of setting it in FLAGS:
./configure --enable-xdebug CC="gcc -arch i386" CXX="g++ -arch i386"
edit3: If, for some unknown reason, you still don’t get the correct architecture, you can manually edit the Makefile and fix the compile flags yourself. The screenshot shows the only 3 differences in resulting Makefile if I ran the ./configure command without (64-bit, left) and with (32-bit, right) the FLAGS settings:
Just open the Makefile in your favorite text editor and adjust the flags directly.
When the compilation finishes, you can verify that the module was built 32-bit, by running:
> lipo -info modules/xdebug.so Non-fat file: modules/xdebug.so is architecture: i386
The architecture should be reported as i386. When you get x86_64, then your configure didn’t succeed in setting the architecture and you should revert to step 4.
6. Copy files
Copy the files to PHP extensions directory. You might need to adjust the path for your XAMPP and PHP version:
sudo cp modules/* /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/
7. Configure PHP.ini
Final step is to configure php.ini file. So open /Applications/XAMPP/etc/php.ini with your favorite editor and add the lines to the bottom of it:
[xdebug] zend_extension=/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so xdebug.remote_enable=on xdebug.remote_handler=dbgp xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000
So that debbugger is connected on every page load.
NOTE: this is not reccommended in production environments as it degrades performance! Now restart Apache and you should be good to go.