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
PhpStorm had it's share of trouble as well, but yesterday I experienced a working debug session. Just like that, deep variable inspection and stepping through the code just worked. Today I looked into CLI debugging because Robert needed that for some complicated FLOW3 task. Also works, although it requires one step that should not be needed. Anyway, here we go.
Environment
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 the red telephone button so it turns into a green telephone button) 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:
export XDEBUG_CONFIG="idekey=PHPSTORM"
some/script.php
Now PhpStorm should pick up your debug request and stop at the first line or breakpoint.
Some hints
- 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.
Tyler Style |
I came across this post while looking for info on troubleshooting xdebug profiling. I've put up a (much more detailed) tutorial on using PhpStorm with a LAMP server and Ubuntu client myself (http://www.mysolutions.it/phpstorm-server-xdebug-configuration/), so I thought I'd link to it here as it might help future visitors with troubleshooting their setup.
K_Wasseem | 15.11.2011
Karsten, you can equally do it with Netbeans just as fine :)
I will try to write one for netbeans/xdebug, I will hit you up with it..
Cheers!
//Wasseem
Mr. F | 01.04.2011
thank you, this worked!, i've been searching all over place for this, i'm using wamp 2.1 + firefox 4 + phpstorm 2.0.1. Thanks again.
jc | 16.02.2011
Thanks for the step by step description it was really helpful.
Crag | 11.02.2011
Also, if you use the Xdebug plugin (for safari or Firefox) it gets easier. You can get both at xdebug.
Ridho | 03.10.2013
thx for the feedback post about NetBeans for PHP. I know the dev team is alyaws looking for ways to improve support. Also, another place to get the latest info is blogs.sun.com/netbeansphp@Kevin lots of good reasons to try out NetBeans for PHP: standard IDE features, integrated JavaScript editor and debugger for IE/Firefox, Database tools (explorer and SQL editor) all in a 20+ mb download.
Uniuni | 14.10.2013
on September 27, 2008I use Eclipse with the PHP Extensions since a couple of years now and its genittg better all the time. Did you use that before?I could imagine switching, even though I had to learn how to use that new IDE, but I wonder if there are good reasons Do you know some?