Monday, November 1, 2010

How To: Install and Configure Xdebug

We will be using RHEL / CentOS as operating system for this tutorial. For more information about installing Xdebug, get it here.

1. Assuming that you have PEAR/PECL installed, get Xdebug by,

# pecl install xdebug

The command above will install the xdebug.so module to your php modules directory which is usually located at /usr/lib64/php/modules (part of distribution) or /usr/local/lib/php/modules (user installed).

2. Activate the xdebug module by adding the following entry to php.ini.

zend_extension = /path/to/xdebug.so or zend_extension = xdebug.so

Note: xdebug is a zend extension, DO NOT use "extension=xdebug.so". This will fail.

You can place the entry above to php.ini by doing any of the following:

# vi /etc/php.ini, copy and paste into a line within the config, then save (ESC + colon + wq)
Or, if your php configuration was installed using dependency structure (/etc/php.d), you can simply do the commands below. This is to separate global and module-specific PHP configurations and make the specific ones unobtrusive as possible to the global settings in maintenance terms.

# cd /etc/php.d
# vi xdebug.ini, copy and paste into a line within the config, then save (ESC + colon + wq)

To configure, you can use the sample below, and paste it after the "zend_extension = /path/to/xdebug.so" module entry.

Xdebug Automatic Mode:

xdebug.profiler_enable = on
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name => cachegrind.out.%t-%R

Xdebug Trigger Mode:

xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name => cachegrind.out.%t-%R

Xdebug Remote Debugger/Debugging:

xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000


3. Restart apache for changes to take effect.

# /etc/init.d/httpd restart

4. To test, run the following.

# php -i | grep xdebug

It should show you something like this:

xdebug
xdebug support => enabled
xdebug.auto_trace => Off => Off
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.file_link_format => no value => no value
xdebug.idekey => root => no value
xdebug.manual_url => http://www.php.net => http://www.php.net
xdebug.max_nesting_level => 100 => 100
xdebug.overload_var_dump => On => On
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_autostart => Off => Off
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.scream => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

If you see something like it and the configuration that you've properly set, then you should have XDEBUG working in your server.

This content originally came from here. It was separated for better usability and autonomy of the topic.
  • Related Links Widget for Blogspot

1 comment:

nitish pandey said...

If on RHEL installation your pecl doesn't seem to be running don't loose hope. Run it like this:
$path_to_php_binary /usr/local/lib/php/peclcmd.php

And rest remains same. I wonder why they do these tiny tricks to frustrate the users. Ugghhhh!