For a long time I have been waiting for a PHP debugger that works. Until now, that was only ever half the case.
- Eclipse required me to set up overly complicated debug profiles
- NetBeans was also going into that direction
- MacGDBp always triggered and allowed to step through the code, but variable inspection is broken
I use PHP 5.3.3, Xdebug 2.2.0-DEV and PhpStorm 2.0 (build 103.78). All this should work with Xdebug 2.1.0 as well, though.
Debugging through the browser
In PhpStorm you need to configure nothing, really. For the sake of it, have a look at the settings in "PHP > Debug". Here are mine:
So far I have no setup in "PHP > Servers" and nothing in "PHP > Debug > Skipped paths". Also, no run configurations are set up so far, just make sure the IDE key is set up:
Then, install the PhpStorm debugging bookmarklets (or some other Xdebug trigger), tell PhpStorm to listen for incoming connections (click so it looks like ) and start a debug session using the IDE key you gave to PhpStorm as well. If all is well, a window should pop up:
Simply click Debug and off you go.
Debugging CLI scripts
For CLI scripts this "zero config" setup does not work (it does for MacGDBp, so, please fix it), thus you need to do some extra work. Create a server configuration in the settings:
And a debug configuration through "Run > Edit configurations":
Now start the debug session manually in PhpStorm ("Run > Debug...") and select the "Unnamed" debug configuration. PhpStorm should then open the debug panel and tell you it is waiting for an incoming connection. Now call your CLI script:
Now PhpStorm should pick up your debug request and stop at the first line or breakpoint.
- If you happen to have code in an excluded directory, e.g. for autogenerated things, you can step through them, but will do so blindfold, as PhpStorm does not ignore those files.
- Explore the options for watches and breakpoints, like conditions. Some powerful stuff is hidden there...
I hope this post helps you with debugging, feel free to leave comments with further tips and (hopefully) success stories.