Monday, February 15, 2010

How to debug PHP scripts on your Mac

I use a MacBook as one of my development machines. For LAMP development I've been using the excellent setup provided by MAMP


Coming from a background in other languages that have readily available debuggers I've been longing for a debugger to help stepping through PHP code and inspecting the content of variables. I found out that some commercial IDEs come with such capabilities out-of the box, but I've been looking for a stand-alone solution, similar to GDB. I can highly recommend xdebug for that. 


Installing it on MAMP was a breeze, by following the excellent instructions from technosophos. The only changes from those instructions were that the latest versions of MAMP (I use version 1.8.4) come with an xdebug.so already present (i.e. /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so), so all you need is uncommenting the zend_extension entry in the php.ini. 


Coupled with the MacGDBp client, the xdebug provides exectly what I've been looking for. Just pay attention to the need to press the reset button in order to initiate a new debugging session when your web page loads.

1 comment:

clod said...

I am using CodeLobster IDE for it