PHP, Xdebug and PhpStorm - working!

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.


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.

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.


Crag said...

Also, if you use the Xdebug plugin (for safari or Firefox) it gets easier. You can get both at xdebug.

jc said...

Thanks for the step by step description it was really helpful.

Mr. F said...

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.

K_Wasseem said...

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


Tyler Style said...

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, so I thought I'd link to it here as it might help future visitors with troubleshooting their setup.

clod said...

I like to use Codelobster PHP Edition for it.

Tùng Lê said...

can you explain this step:
Now call your CLI script:

jowdjbrown said...

In all honesty this was one of my favourite blog posts that I have ever come across, please carry on blogging, you are a true asset to the blogging community.LKW chiptuning

Mickey James said...

They did a great job in repairing the ZehnBesten AC in my Excursion, Great Service, and Detailed explanation of what was done to my AC. I highly recommend them. Exceptional service and extremely honest. My AC was repaired at minimal cost and I saw firsthand why their reviews are perfect. I would highly recommend this company for your auto repair.

Tanika Co Valda said...

I have read your blog its very attractive and impressive. I like it your blog.

PHP 7 Training in chennai | PHP 7 Training Course

PHP 7 Training in chennai | Online PHP 7 Course

sheela said...

Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
Best Devops online Training
Online DevOps Certification Course - Gangboard

sasitamil said...

It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.

Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Selenium training in bangalore

cathryn leno said...

This is a good post. This post give truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. thank you so much. Keep up the good works.
python training Course in chennai
python training in Bangalore
Python training institute in bangalore