xdebug with XAMPP on Mac OS X

Xdebug logoI 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

3. PHPIZE

Run phpize

/Applications/XAMPP/xamppfiles/bin/phpize

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.

5. Make

make

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:

xdebug.remote_autostart=1

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.

Be Sociable, Share!

No related posts.

Leave a comment ?

23 Comments.

  1. I discover all local variables display as ” “. Could you have this problem?

  2. I discover all local variables display as ‘Uninitialized’. Could you have this problem?

  3. Something does seem to be broken with this setup, because now my app does not break at the breakpoints.

    I will look into it.

  4. 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.

    Thank you!

  5. When I run
    /Applications/XAMPP/xamppfiles/bin/phpize

    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?

  6. Are you in the xdebug folder? Can you yourself see the config.m4 file?

    I have it like so:

    $ pwd
    /Users/laas/proged/xdebug
    $ ls config.m4
    config.m4

  7. Xdebug 2.1.1 for XAMPP OSX 1.7.3 | mrclay.org - pingback on 22. apr 2011 at 08:20
  8. Hi,

    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?

    Thanks

  9. Hi Roosevelt,

    Can you check that you configured Xdebug with i386 support as XAMPP is still compiled for i386/ppc, not x86_64.

    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 i386 as 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.

  10. Works like a charm on Mac OS 10.6.8. Thanks.

  11. 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:

    --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config

    I had to make this:

    --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1

    I am using XAMPP 1.7.3

  12. 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

  13. 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)

  14. Thank you very much!

  15. Things like this is what makes Internet great! :grin:

    Thanks a lot!

  16. Cedric Talbot

    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.

  17. I am on MAC Lion; and I have to run command like this

    ./configure –enable-xdebug CC=”gcc -arch i386″ CXX=”g++ -arch i386″

  18. 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.

  19. 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 :grin:
    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.

  20. 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

  21. 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

    creating libtool
    appending configuration tag "CXX" to libtool
    configure: creating ./config.status
    config.status: creating config.h
    config.status: config.h is unchanged

  22. Hi Jeremiah,

    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).

  23. Hi,

    Can anyone please help me here I have to install the xdebug from the Git

Leave a Comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackbacks and Pingbacks: