Debugging with Xdebug - DoSomething/legacy-website GitHub Wiki

Vagrant box (>= v1.0.0.rc2) is shipped with pre-configured php5-xdebug package which allows you to debug your code using IDEs compatible with DBGp protocol.

In this article explained how to connect Sublime Text to remote Xdebug, but most steps are general for any IDE.

Install IDE debug client

If your IDE is not bundled with DBGp-compatible debugger, install a plugin with Xdebug support.
For Sublime Text, you'll need Xdebug Client package.

Setup the client

Edit the project, corresponding to dosomething-mount folder. You'll need set two things in your IDE:

1. Set IDE key

IDE key inside the box is set to vagrant. Make sure your project uses same Xdebug key to communicate with it.
In Sublime Text, edit the project:

  • Into "settings" section, add "vagrant" array and set "ide_key": "vagrant" inside it:
{
  "settings":
  {
    "xdebug": {
      "ide_key": "vagrant",
    }
  }
}
2. Map the folders

Xdebug needs to know how files and folders on your drive correspond with same files and folders inside Vagrant.
In Sublime Text, you can set it in the same "xdebug" section, where you set your "ide_key". Let's assume, you have your project located in /Users/sergii/Development/dosomething-mount/:

{
  "settings":
  {
    "xdebug": {
      "ide_key": "vagrant",
      "path_mapping": {
        "/var/www/dev.dosomething.org/html": "/Users/sergii/Development/dosomething-mount/html",
        "/var/www/dev.dosomething.org/lib/modules/dosomething": "/Users/sergii/Development/dosomething-mount/lib/modules/dosomething",
      },
    }
  }
}

Debug

1. Enable debugging in your browser

Most browser has convenient plugins to turn on/off debugging. For Chrome you can use Xdebug helper.

You'll need to set ide_key in the plugin settings as well. For example, here's Xdebug helper configuration:
image

Then you'll be able to enable debugging easily: go to http://dev.dosomething.org/ and click the bug icon at the end of Address Bar:
image

From now on, on every page refresh, Xdebug will be attempting to connect to your IDE debugger on port 9000.

2. Set some breakpoints

For test purposes, open index.php and set a breakpoint at one of lines:
image

3. Turn on the debugger

image

4. Debug!

Go back to the browser and hit refresh. If everything worked out, you'll get your context variables in IDE: image