How to set up and use Xdebug

From Kunena Wiki
Jump to: navigation, search


How to set up and use Xdebug

Xdebug is a nice tool, to help the developpers to debug their code in php and can be integrated easily into Eclipse/Zend Studio.

Instead of see this kind of error :

Simple error display by default by Php

You will see that :

Error more detailled with Xdebug



If you using, windows with wamp, you have just to download the xdebug dll.

For Php 5.2.x : [Download]
For Php 5.3.x : [Download]

Put your xdebug dll in this directory : c:\wamp\bin\php\phpx.x.x\

You need to edit your php.ini file which can be found in C:\wamp\bin\apache\Apache2.2.11\bin\php.ini

xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "c:/wamp/tmp/"


For linux and in particular debian or derived distribution, you need to install first these things :

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

and then

pecl install xdebug-beta 

Your php.ini file is probably here : /etc/php5/apache2/php.ini

Then, you need these lines at the end of your php.ini file :


; Remote settings

Then, restart apache service and you will see in your phpinfo a section with xdebug, it's not the case you type a wrong path for the xdebug library.

Some configuration settings

You can add/remove differents settings into your php.ini file, to adapt the xdebug configuration at you needs : [xdebug settings]

You can add this by example to show all local variables of the code which cause the error :


The [php fucntion var_dump()] is very useful when you do debugging, but Xdebug improve the organisation of output of this function to show detailled results, by example with this kind of code :

$a = array(1, 2, array("a", "b", "c"));
$b = 3.1;
$c = true;
var_dump($b, $c);

echo '<hr />';

var_dump($b, $c);

You will see that with Xdebug :

Xdebug improved output of var_dump()

You can too the Joomla! extension nammed [J!Dump] which do the same thing but for print_r() or var_dump().

Integration with Eclipse/Zend Studio

Now, open Eclipse or Zend Studio and go into Window -> Preferences, choose then the menu Php -> Debug

Xdebug settings in Eclipse or Zend Studio

In the first dropdown list, select Xdebug and in the second dropdown list, keep the default if you have your server on localhost.

Debug with Xdebug into Eclipse/Zend Studio

Now, open your project into Eclipse/Zend Studio, then open a php page, to launch the debug mode do : Debug As -> PHP Web Page. This will open a new windows of the default browser which is set in eclipse and open a new perspective in eclipse for debugging (you can the perspective in the top right of eclipse).

The debugging perspective is splited into five windwows :

  • In top left, you see a debugging window which give you information of the current debugging and offers to you a debug toolbar.
  • At right, you can see the variables of your code and breakpoints.
  • Below, you see your code that you are working, with the current line which is highlighted and you can too remove/set breakpoints.
  • Below this, the window console which displays warnings.
  • And completly at right, you see the output window.

When you use debugging functions on eclipse, you will see the changes made on your browser.

to be completed

Tracing code

[Tracing code]

Profiling code

[Profiling code]

Personal tools

Interface Language