VIM, Xdebug, and PHP 5.3 (compiled from source) on Arch Linux

Posted by jason on June 1, 2011, 5:28 p.m.
Tags: arch linux php vim xdebug

I finally got sick of using echo statements to debug my PHP scripts, so I decided to install xdebug and use it from within VIM. I followed this guide, but there were some things that were specific to my setup--namely, using Arch Linux with PHP 5.3 compiled from source.

Here's what I had to do:

Recompile PHP

I had compiled PHP, but I didn't run ./configure with the "--enable-debug" flag. So I went to where I had originally compiled PHP (in /usr/local/src/php-5.3.6) and did the following:

  • Found the "./configure" command that was used in my current PHP install. The command and its parameters can be found in the config.status file in your PHP source directory (/usr/local/src/php-5.3.6)--or you can run phpinfo() and get it'll show up there.
  • Run the old configure command with --enable-debug. You might need to get rid of --disable-debug if it's there.
  • Run "make", "make install".
  • Restart apache: /etc/rc.d/httpd stop; /etc/rc.d/httpd start (Doing "restart" didn't seem to work for me in this case--maybe because I just installed a newly compiled version of PHP?)

Compile xdebug

  • Go to the xdebug download page and download the source code.
  • Go here, paste your phpinfo() output, and follow the instructions.
  • If you want, copy the "modules/xdebug.so" file somewhere. I don't care where. Just make sure you know where the file is no matter what you end up doing with it.

Install VIM with +python

Run vim, type ":version", and see if you have "-python" or "+python". If you have "-python", then that means you need to install VIM with python support. The easiest way to do so is to install gvim:

pacman -S gvim

Pacman will tell you that it's going to remove the "vim" package--that's fine: gvim installs vim with more things enabled (like python).

Install vim-debugger

This step is easy:

yaourt -S vim-debugger

Enable xdebug in PHP

Edit your php.ini file and add the following under the "Module Settings" section:

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

zend_extension=/path/to/my/xdebug.so
[debug]
; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000

; General
xdebug.auto_trace=off
xdebug.collect_includes=on
xdebug.collect_params=off
xdebug.collect_return=off
xdebug.default_enable=on
xdebug.extended_info=1
xdebug.manual_url=http://www.php.net
xdebug.show_local_vars=0
xdebug.show_mem_delta=0
xdebug.max_nesting_level=100
;xdebug.idekey=

; Trace options
xdebug.trace_format=0
xdebug.trace_output_dir=/tmp
xdebug.trace_options=0
xdebug.trace_output_name=crc32

; Profiling
xdebug.profiler_append=0
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=0
xdebug.profiler_output_dir=/tmp
xdebug.profiler_output_name=crc32

Try it out

Everything should be ready to go now. Restart apache and run phpinfo() to see if any xdebug information comes up. If it doesn't, then the apache error_log + google are your friends.

Otherwise, you are ready to run the debugger inside vim.

  • Open a PHP script in VIM that you can access from your localhost
  • Open that same PHP script in your web browser
  • Add ?XDEBUG_SESSION_START=1 to the end of the URL
  • In VIM, press F5. You should see at the bottom of VIM like "waiting for a new connection on port 9000 for 10 seconds..."
  • Within the next 10 seconds, refresh the browser page with the "?XDEBUG_SESSION_START=1" on the end of the URL.
  • Go back to VIM and you're in the debugger in all its glory.
  • Don't forget: to switch between windows in VIM, press CTRL-w-w.

0 comments