Setting up xdebug/DBGp for PHP on Debian/Ubuntu

Published Sat, 2006/12/23 - 18:10

Developers frequently need to trace the execution of their code, and debug it, and Drupal/PHP is no exception.

There are several PHP debugging frameworks/APIs available, including DBG, Gubed, Zend, and xdebug. Each of those supports different IDEs (Integrated Development Environments).

This article focuses on xdebug, and how you can set it up on your development machine or server.

xdebug provides the ability for more than one person to have debug sessions concurrently on the same server, using the DBGp protocol. Not all IDE's available support this feature however.

IDEs that use DBGp at present are:

  • Vim with the xdebug plugin (command line, non-GUI).
  • ActiveState Komodo (multi-platform)
  • Quanta Plus (KDE on Linux)

Installation

To install xdebug on a debian/Ubuntu system enter the following commands from sudo bash or root shell:

First, install PHP and MySQL if you already do not have them. You may not need the gd library if you do not have image manipulation modules.

aptitude install apache2 php5 php5-gd mysql-server php5-mysql

Next, install PHP development, Apache development, and PEAR.

aptitude install apache2-dev php5-dev php-pear make

Lastly, install xdebug using PHP's pecl

pecl install xdebug-beta 

This last step will run for a while, compiling xdebug from source. It should not have any errors. 

Configuration

After the last command completes, you will have an xdebug.so library. You now need to configure apache to use it.

To do this, edit your PHP configuration file /etc/php5/apache2/php.ini and add in it the following section just before the [Date] heading:

zend_extension=/usr/lib/php5/20051025/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

If you are using this on a server that is separate from the machine that you run the IDE in, then change the host name in xdebug.remote_host from localhost to the name of your server.

You can now use an IDE that supports DBGp to debug PHP applications, including Drupal.

Vdebug

If You use Vim, check out Vdebug plugin:
http://www.vim.org/scripts/script.php?script_id=4170

these settings didn't work for me

In Netbeans 6.8 I kept getting "java.net.SocketException: Broken pipe" errors soon after hitting a breakpoint, which would terminate the debugging session.

I just used this, which worked


; Remote settings
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

xdebug - code coverage

Profiling worked just by following the steps. It seems xdebug also does code coverage, how do we view it in report format?

Error in Configuration chapter

It reads:
If you are using this on a server that is separate from the machine that you run the IDE in, then change the host name in xdebug.remote_host from localhost to the name of your server.

Should be:
If you are using this on a server that is separate from the machine that you run the IDE in, then change the host name in xdebug.remote_host from localhost to the name of your machine where you run your IDE in.

Memory limit

I got an error message about the memory limit being exceeded when running pecl, to fix this open /usr/bin/pecl and change the line

exec $PHP -C -n -q $INCARG -d output_buffering=1 -d safe_mode=0 $INCDIR/peclcmd.php "$@"

to

exec $PHP -C -n -q $INCARG -d output_buffering=1 -d safe_mode=0 -d memory_limit=24M $INCDIR/peclcmd.php "$@"

Another HOWTO

There is another HOWTO that describes a bunch of useful Ubuntu apps/configs (including XDebug) for Drupal devs.

You can see it at Free development environment.

Is your Drupal or WordPress site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal and WordPress Performance Optimization and Tuning Consulting