Tabla de Contenidos

Debugging PHP with Vim + Xdebug + Vdebug

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 Vdebug

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 ~/.vim/bundle/vdebug

Install and configure XDebug

Install the xdebug package for your distribution. Either:

apt-get install php5-xdebug


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

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

Configure vdebug

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': ''}
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.

How to use vdebug

How to redefine vdebug's keys

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 .

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

<Volver a la sección de GNU/Linux>