Every 6 months or so I take a stab at setting up line-level, breakpoint style debugging for PHP. In the past I've been able to get the debugger installed, but the lack of a decent interface to use in setting breakpoints and watches has limited the value of a debugger (one thing that I have found helpful is XDebug's profiling feature that lists all function calls in a nested format along with performance timing). The recent announcement of a new XDebug client for OS X got me back on that track, and while I wasn't able to get MacGDBP working as I wanted, it did lead me to re-evaluate the newest Eclipse offering for PHP coders: PDT. PDT has come a long way, and the combination of a robust IDE, nimble 'jumpt to' shortcuts and killer debugger integration are more than I can pass up. Here's how I got everything working on a Mac OS X 10.5 box.
Much of what follows was made possible by and incorporates instructions from these very good tutorials:
MAMP folder into your Applications folder. You can then start up the MAMP application to make sure everything is working (it should load a test page to confirm once the Apache and MySQL servers have booted).Using this MAMP distribution makes installing XDebug as simple as running the command sudo /Applications/MAMP/bin/php5/bin/pecl install xdebug. Really. Once this is done just add the following lines to your php.ini file in /Applications/MAMP/conf/php5/php.ini (note that the location of the .so file is not the same as the extension files that ship with MAMP, since the XDebug version is more recent than those builds):
zend_extension="/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
[Xdebug]
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
xebug.remote_handler=dbgp
Now, stopping and then starting your MAMP Apache server using the MAMP application in Applications/MAMP should give you an XDebug-enabled PHP install running on port 8888 (the MAMP default). To check that everything’s working as it should, click the “Open Start Page” button in the MAMP application window (though it should have automatically opened when you restarted Apache), then on the “phpinfo” link in the top nav of that page. Searching in this page should turn of a number of references to XDebug, including a section devoted to various XDebug variable settings.
(screenshot)
PDT has been “in development” for a long time, but after about a week of working with it I have to say I’m very impressed. I still prefer coding in Textmate, but since PDT has everything I need in a text editor (jump to file and jump to function keystrokes, mainly…though I can’t find out how to easily set markers for quick jumping to specific lines) and also support line-level debugging, I’m moving much of my coding to the PDT IDE environment. In addition the downloadable all-in-one distribution of Eclipse, PDT and all required Eclipse modules for PDT makes installation a real snap:
/Applications/MAMP/htdocs (personally I use virtual hosts, but more on that later), you’ll need to start a new PHP project in Eclipse using the exiting code from your Drupal directory. To do this, start Eclipse then go to the Workbench view (if you get the odd startup screen when you start Eclipse). Select “New Project” from the “File” menu, then choose “PHP Project” from the nested listing in the following window. Name your project something appropriate then uncheck the “Use Default” under “Project Contents” and Browse to the folder containing the Drupal project you want to debug (or any other project, for that matter)..module and .engine files as PHP, open the Preferences screen in Eclipse and then choose General->Content Types from the settings tree on the left of the window. Expand the “Text” tree in the “Content Types” textarea and choose “PHP Content Type” entry then click the Add button next to the “File Associations” listing twice, adding entries for “*.module” and “*.engine”.Now for the fun part.
/Applications/MAMP/bin/php5/bin/php if you want to use the php binaries provided with MAMP. Up next: using PDT, Eclipse and XDebug to debug and reverse engineer Drupal code!
For others having trouble
For others having trouble setting this up with MAMP PRO, note that it uses a separate instance of the php.ini file from the regular version. In order for XDebug to load, you must changes to the version located at:
/Library/Application Support/living-e/MAMP PRO/conf/php.iniMake sure you have XTools
Make sure you have XTools fully loaded before trying the pecl command otherwise you'll get this error :
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
environment variable is set correctly and then rerun this script.
Thanks for this well-written tutorial.
cheers
You're a lifesaver! Thank
You're a lifesaver! Thank you!!
I'm getting Page Not Found
I'm getting Page Not Found when I click the screenshots. Any chance of updating the links?
Thank you for your wonderful
Thank you for your wonderful post. It was very helpful. How does one begin to use PDT to debug a module? I'm assuming you set a breakpoint in the module. How does one then begin execution using a browser to activate the debugger on a drupal site? Any help would be appreciated.
Anyone got this working do
Anyone got this working do debug a module ?
Can't get the scripts to break in my .module file.
Don't know what I'm missing....
The debugger works just fine outside the drupal implementation.
Post new comment