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