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 Box.net 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 Box.net 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 Box.net article.
- Download XDebug and put it in xampplite\php\ext
- Edit xampplite\apache\bin\php.ini. Add these lines:
zend_extension_ts="c:/xampplite/php/ext/php_xdebug-2.0.3-5.2.5.dll"xdebug.remote_enable = 1xdebug.remote_port = 9000xdebug.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 debugger.py to work with windows paths, so open debugger.py in gVim
- Change the session file to something reasonable. XAMPP has a directory that already serves this purpose, so you might change
self.sessfiletoself.sessfile = "C:\\xampplite\\tmp\\debugger_vim_saved_session." + str(os.getpid()) - Now change every occurance of
getAttribute['filename'][7:]togetAttribute['filename'][8:]. Do the same withgetAttribute['fileuri'][7:]
- Change the session file to something reasonable. XAMPP has a directory that already serves this purpose, so you might change
- Open up a browser and append
?XDEBUG_SESSION_START=1to the end of an address on your local webserver. - Open gVim. Hit F5, then refresh your browser page. You should now be debugging!
Hey Blake, thanks for the tips. I am so close to getting this working. Hope you can help…
Developing on WinXP with GVIM connected via sftpdrive to the remote Ubuntu box with the website on it.
Set up php.ini for remote debugging on my local WinXP IP.
I edit the file in vim, hit F5, refresh the page in firefox. It connects, but I get the following error in gVim:
E185: Invalid buffer name: var/www/{siteName}}/htdocs/filename.php
Seems to me that its trying to map the same directory structure on my locally mapped drive (via sftp) to the one on the webserver and they don’t match.
Any ideas? Any help appreciated. Thanks.
Hi David,
It sounds like you need to modify the paths that debugger.py is trying to open. I actually don’t do any python programming myself, so I can’t give you specifics, but I would imagine that you want to write a function which takes in a linux path and maps it to your sftpdrive path.
In PHP your function would look like
function remap( $path ) { return ‘F:' + preg_replace( ‘%/%’, ‘\’, $path ); }
where “F:” is the drive letter of your sftpdrive. Then you want to wrap every reference to getAttribute[‘filename’][7:]. You just need to convert my function to Python.
If I am not mistaken, in Python my function would be:
def remap (path): return ‘F:\’ + path.replace(‘/’, ‘\’)
Thanks Blake,
It’s more complex than that, since the full paths are not even close.
I gave up on it.
Thanks for your efforts though.