Debugging PHP on Windows with XDebug and VIM

Habari is a sufficiently complex PHP application that sometimes the only way to figure out what is going on is to fire up a debugger. Following a suggestion on #habari and some google searching, I found an article on the blog on using XDebug with vim. The instructions were for a linux box, and I initially struggled to get things working on Windows (XAMPP). But, I finally got it through digging through the comments on the article and Vim documentation. I thought it would be useful to gather the required steps in one place, so here are my instructions:

  • Read the article.
  • Download XDebug and put it in xampplite\php\ext
  • Edit xampplite\apache\bin\php.ini. Add these lines:
    xdebug.remote_enable = 1
    xdebug.remote_port = 9000
    xdebug.remote_host = localhost
  • Restart Apache. Check that xdebug appears on your phpinfo() page.
  • Download the xdebug plugin for Vim and put it in: C:\Program Files\Vim\vim71\plugin
  • Download and install Python 2.4 (not 2.5). You can see which version of Python your copy of gVim is looking for by looking for the 'python' string in the gVim binary (dirty, but it works!)
  • Now you need to modify to work with windows paths, so open in gVim
    • Change the session file to something reasonable. XAMPP has a directory that already serves this purpose, so you might change self.sessfile to
      self.sessfile = "C:\\xampplite\\tmp\\debugger_vim_saved_session." + str(os.getpid())
    • Now change every occurance of getAttribute['filename'][7:] to getAttribute['filename'][8:]. Do the same with getAttribute['fileuri'][7:]
  • Open up a browser and append ?XDEBUG_SESSION_START=1 to the end of an address on your local webserver.
  • Open gVim. Hit F5, then refresh your browser page. You should now be debugging!