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
EDIT: As pointed out by strah below, if you’re going to use MacGDBp for debugging GUI, you need to add additional line to php.ini file:
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.
24 thoughts on “xdebug with XAMPP on Mac OS X”
I discover all local variables display as ” “. Could you have this problem?
I discover all local variables display as ‘Uninitialized’. Could you have this problem?
Something does seem to be broken with this setup, because now my app does not break at the breakpoints.
I will look into it.
You’re a lifesaver! I’ve been banging my head against a wall all night trying to resolve this issue and your solution works perfectly.
When I run
I get this error:
Cannot find config.m4.
Make sure that you run '/Applications/XAMPP/xamppfiles/bin/phpize' in the top level source directory of the module
Could you please tell me how to resolve it?
Are you in the
xdebugfolder? Can you yourself see the config.m4 file?
I have it like so:
$ ls config.m4
[…] contains a freshly compiled xdebug 2.1.1 module for XAMPP OSX, using this tutorial as a guide. The archive contains step-by-step install instructions w/ bash […]
I need to setup xdebug on my 64-Bit Mac OS X Leopard, and your post is the most relevant one I can find for my needs. I have XAMPP working fine and after I generate the xdebug.so file, i receive the following error:
Failed loading /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so: dlopen(/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so, 9): no suitable image found. Did find:
/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so: mach-o, but wrong architecture
Can you please help me?
Can you check that you configured Xdebug with
i386support as XAMPP is still compiled for
To do that, run:
lipo -info /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so
And see that it lists
i386as an architecture. If it does not, please recheck step 4 above, to set appropriate flags for the compiler.
BTW, I switched my XAMPP for a self-compiled apache and did not need xdebug anymore, so I haven’t recompiled it since. But I still hope this post is not that outdated and still aplies.
Works like a charm on Mac OS 10.6.8. Thanks.
Getting Xdebug to work was a total pain. Thanks for the post! I had to make one small modification, however. On step four you have:
I had to make this:
I am using XAMPP 1.7.3
Just to correct one command above so you are not pulling your hair out:
./configure CFLAGS="-arch i386 $CFLAGS" CCFLAGS="-arch i386 $CCFLAGS" CXXFLAGS="-arch i386 $CXXFLAGS" LDFLAGS="-arch i386 $LDFLAGS" --enable-xdebug --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config
You are right of course – ./configure does prefer env variables to be specified as arguments (though prepending should work in Bash/sh which evaluates variable specifications preceding the commands)
Thank you very much!
Things like this is what makes Internet great! 😀
Thanks a lot!
I followed your instructions and ran into a problem with the phpize command, because autoconf wasn’t available on my system. To work this out I installed Xcode via the Mac App Store, then I installed the Xcode Command Line Tools (via the Xcode prefs -> downloads pane), then I had to set the Xcode folder with the command line tool xcode-select (I set the folder to /Applications/Xcode). After all that, I installed macports to get autoconf… Without the Xcode command line tools, and the xcode-select configuration, macports refused to operate which explains all the steps. Hope this helps others as well.
I am on MAC Lion; and I have to run command like this
./configure –enable-xdebug CC=”gcc -arch i386″ CXX=”g++ -arch i386″
This won’t work with the latest version and Lion. To solve it use an earlier version. I think I eventually got 2.1.2 to work. 2.2.0 is the latest and doesn’t play well with Lion. You also can’t use the pre-compiled version. It’s a bitch to install on OS X. Anyhow, this post is one of the best I’ve seen because you’ve updated the post as these brilliant comments come in. Thanx for posting. Very helpful.
Thank you very much for the detailed walk-through, everything installed without any problems even on Mac OS X 10.8 and xampp 1.7.3 😀
However there is one thing that I’d like to mention for all people using MacGDBp as a GUI for xdebug: You need to add “xdebug.remote_autostart = 1” to the php.ini configuration of xdebug to get MacGDBp to automatically kick in whenever a php file is run.
Thanks a lot. Works great.
Just want to emphasize … as mentioned in comments above make sure your architecture is i386
lipo -info /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so
This has been the best explanation of why I get the architecture issue when attempting to use Xdebug in my dev environment.
I have been going in circles getting AMPPS configured on a Mac OSX 10.8 with PHP debugging. I consistently get the wrong architecture. I tried both methods of changing the architecture listed here in the blog post (thank you), but I still get a x86_64 architecture when running ‘sudo make install’.
I’ve included the terminal output below for reference to the process. Any ideas on why I can’t seem to compile in the right architecture would be appreciated.
xdebug-2.2.2 jeremiah$ ./configure --enable-xdebug --with-php-config=/Applications/AMPPS/php-5.3/bin/php-config CFLAGS="-arch i386 $CFLAGS" CCFLAGS="-arch i386 $CCFLAGS" CXXFLAGS="-arch i386 $CXXFLAGS" LDFLAGS="-arch i386 $LDFLAGS"
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i386-apple-darwin12.3.0
checking host system type... i386-apple-darwin12.3.0
checking target system type... i386-apple-darwin12.3.0
checking for PHP prefix... /Applications/AMPPS/php-5.3
checking for PHP includes... -I/Applications/AMPPS/php-5.3/include/php -I/Applications/AMPPS/php-5.3/include/php/main -I/Applications/AMPPS/php-5.3/include/php/TSRM -I/Applications/AMPPS/php-5.3/include/php/Zend -I/Applications/AMPPS/php-5.3/include/php/ext -I/Applications/AMPPS/php-5.3/include/php/ext/date/lib
checking for PHP extension directory... /Applications/AMPPS/php-5.3/lib/extensions/no-debug-non-zts-20090626
checking for PHP installed headers prefix... /Applications/AMPPS/php-5.3/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable eXtended debugging support... yes, shared
checking Check for supported PHP versions... supported (5.3.21)
checking for gettimeofday... yes
checking for cos in -lm... yes
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... no
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 196608
checking command to parse /usr/bin/nm output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fno-common
checking if cc PIC flag -fno-common works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin12.3.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
From your output, I can’t tell what went wrong (probably because ./configure does not report setting the flags).
I’ve confirmed that above method still does produce 32-bit binary in Mac OS X 10.8.3 Mountain Lion.
Also, I updated the step 4 above and added a screenshot of Makefile differences that should help you to adjust your Makefile manually. If that still doesn’t produce 32-bit binary, then I’m afraid, this goes beyond my knowledge of Mac OS X compiler settings (maybe there is a global forced setting somewhere deep in system etc).
Can anyone please help me here I have to install the xdebug from the Git
Year 2020 – I was using NetBeans all along, but recently migrated to VSCode in an attempt to use a single IDE for all the languages.
Your blog entry is still relevant and helped me a lot in getting up and running with VSCode with xdebug.
I was using XAMPP on Mac so it had a few more steps to go, but overall this was really fantastic.