By Matt Butcher
Installing XDebug 2 on Mac OS 10.6 Snow Leopard (with PHP 5.3)
A while back, I wrote an extensive article on installing XDebug on OS X with MAMP. Now that I have Snow Leopard, I am making a new attempt at working with XDebug on OS X. This article discusses working with XDebug 2.0 or greater on Mac OS 10.6 with PHP 5.3, as packaged with OS X. Continue on for step-by-step instructions. (For more notes on upgrading a PHP dev environment for Snow Leopard, read this article.)
In the past, I have used MAMP because the PHP configuration with which OS X ships with is sub-par. But with Snow Leopard, I am reversing my decision. To my knowledge, Apple is now the first to release a major OS with PHP 5.3 support (beating out Gentoo -- probably a first). And this build of PHP appears to come with all the bells and whistles that I use, including the long-absent GD support, Phar support, and (as long as you have XCode installed) all the header files necessary for building PECL packages.
Yes, Pecl works out of the box. A pleasantry which was certainly not the case with MAMP. And that means that XDebug can be installed very easily.
Make sure that you have XCode installed
You can easily install XCode, Apple's integrated development environment with benefits (IDEWB?). It comes on the Snow Leopard DVD. Just launch the DVD, go to "additional packages" (or extras, or whatever it's called) and launch the XCode MPKG file.
Install XDebug from PECL
To install XDebug, you need to use PECL. And you will need to run the installer with root permissions, since PHP stores files in places that require root permission to write.
$ sudo pecl install xdebug
This will fetch and compile XDebug's source code, creating the xdebug.so shared object that PHP loads.
Configure PHP to Use the New Library
Now you need to configure PHP to use the new XDebug library. For starters, you might need to create a php.ini file.
The php.ini file should be in /etc. If it is not there, do this:
$ sudo cp /etc/php.ini.default /etc/php.ini
Now, as root, edit the new php.ini file:
$ sudo edit /etc/php.ini
Near the end, you should add something like this:
[xdebug] zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so xdebug.file_link_format="txmt://open?url=file://%f&line=%1" xdebug.remote_enable = On ;xdebug.remote_handler = 'dbgp' ;xdebug.remote_handler = 'gdb' ;xdebug.remote_mode = jit xdebug.remote_autostart = 1
(For more information on what all of this does, see Debugging Your PHP Code)
The first second deserves mention, and may possibly need tweaking on your end. This is the location of the correct xdebug.so file. It should most definitely be somewhere in /usr/lib/php/extensions, though the next directory might be slightly different -- the date stamp might be different.
Once you have saved the php.info file, you should be ready to go. Your command-line PHP environment should immediately pick up this change, while your web server may need a restart.








Thank you for this guide, it
Thank you for this guide, it worked perfectly on Snow Leopard.
Thank you!!!
Hi Matt,
My friend and I have been trying to do this for a few hours now and we finally found your article.
Great!!! thank you for posting, your blog has been bookmarked! Twice!!
Thanks again!
Ben
Troublshooting php.ini
I have had to reconfigure xdebug a few times lately for systems running Snow Leopard, (but this would apply to most *nix installs I think), and I have made the same mistake a few times. I pass this tip along in case it helps someone else:
When editing the php.ini file, usually found in /private/etc, the following information is added:
; Added by me on date
; Xdebug config for Mac OS X and NetBeans IDE
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-{date}/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey=
Notice I have two lines of comments reminding me what I did and when. The way the php.ini files works, if you have one of these comments beginning WITHOUT the ";" then it's not read as a comment, but as a setting. They are not and so the lines following are not read.
When you run phpinfo() you will see that xdebug is not being loaded and you may be left wondering why. No error is given unless you run something like: php -v from the command line in terminal. When you have an error in your php.ini, you will get a response in terminal something like:
PHP: syntax error, unexpected BOOL_TRUE in /private/etc/php.ini on line 1903
PHP 5.3.1 (cli) (built: Feb 11 2010 16:26:40)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
Check to see if you left out a ";". Once you finish editing, be sure to restart the Apache webserver.
Happy debugging!
Thanks!
One step closer to getting the Komodo PHP debugger to work on my Mac.
impossible start with option remote_autostart
Hi,
it's impossible for me to run apache, php with this options xdebug.remote_autostart.
Thank if can help me
Post new comment