How to debug PHP code with Vim + Xdebug thanks to the Vdebug plugin. The example below assumes that you'll use vim as the editor in the webserver itself but you can use it from a different development machine (just adjust the IP addresses as desired).
Install the vdebug plugin so that it's started with your favourite Vim's plugin manager Pathogen/Vundle/plugins. In my case, for pathogen:
# git clone https://github.com/joonty/vdebug.git ~/.vim/bundle/vdebug
Install the xdebug package for your distribution. Either:
apt-get install php5-xdebug
or:
yum install php-pecl-xdebug
Edit the xdebug.ini configuration file to set up xdebug (disabled by default, change to port 10000, disable the profiler, etc):
# cat /etc/php.d/xdebug.ini ; Enable xdebug extension module zend_extension=/usr/lib64/php/modules/xdebug.so xdebug.remote_autostart=1 xdebug.default_enable=0 xdebug.remote_enable=0 xdebug.remote_remote_enable=0 xdebug.remote_host=localhost xdebug.remote_port=10000 xdebug.idekey=netbeans-xdebug xdebug.profiler_enable=0
Now, enable xdebug only in the desired virtualhost:
# cat /etc/httpd/vhosts.d/my_vhost.conf (...) php_flag xdebug.default_enable on php_flag xdebug.enable on php_flag xdebug.remote_enable on (...)
Edit the vimrc file for your developer user in the server and add:
let g:vdebug_options = {'ide_key': 'netbeans-xdebug'} let g:vdebug_options = {'break_on_open': 0} let g:vdebug_options = {'server': '127.0.0.1'} let g:vdebug_options = {'port': '10000'}
The predefined keys are:
<F5>: start/run (to next breakpoint/end of script) <F2>: step over <F3>: step into <F4>: step out <F6>: stop debugging <F7>: detach script from debugger <F9>: run to cursor <F10>: toggle line breakpoint <F11>: show context variables (e.g. after "eval") <F12>: evaluate variable under cursor :Breakpoint <type> <args>: set a breakpoint of any type (see :help VdebugBreakpoints) :VdebugEval <code>: evaluate some code and display the result <Leader>e: evaluate the expression under visual highlight and display the result To stop debugging, press <F6>. Press it again to close the debugger interface.
If you don't feel comfortable with the default keyboard shortcuts for vdebug, you can change them by setting the "vdebug_keymap" variable in your .vimrc.
Keymap example from http://thorpesystems.com/blog/debugging-php-in-vim/ .
" Vdebug let g:vdebug_keymap = { \ "run" : "<Leader>/", \ "run_to_cursor" : "<Down>", \ "step_over" : "<Up>", \ "step_into" : "<Left>", \ "step_out" : "<Right>", \ "close" : "q", \ "detach" : "x", \ "set_breakpoint" : "<Leader>p", \ "eval_visual" : "<Leader>e" \}