Eclipse, PHP, and XDebug

In the past I’ve written how to use Eclipse with phpdbg and ZendDebugger. The phpdbg was short lived as it was replaced with xdebug. According to Zend’s website, they say that there are no serious limitations of xdebug. However, there may be some limitations when working with other Zend modules.

This is not going to be a problem seeing as all I want to do use it to debug web pages. This will work on either Windows, Linux, and possibly MacOS X.

Since posting about Eclipse and Zend, it has gotten much easier to get Eclipse and configure it for PHP. Go to Eclipse’s homepage. On the front page there is a link to download the IDE for other languages; click on that and get the one for PHP.

Before we get started with editing configuration files. I’m going to assume that Apache, PHP, and MySQL is properly configured. If you are using Windows I recommend that you get XAMPP, if you are using Windows.

Download and install the xdebug extension. Depending on your distribution, installation will be a bit different. For Gentoo it’s going to be :

# emerge dev-php5/xdebug


# yum install php-pecl-xdebug

If you download it from xdebug’s homepage, you want to place the into the php extension directory. You can check to see where the file needs to go by running this command:

php -i | grep extension_dir

If you are using WIndows, then make a simple php file and call the phpinfo in the file. Open the file in your browser and get the directory in which the extensions are. After you have done that you need to edit the php.ini file. The key is that you modify the correct one. This is especially important you make sure that you edit the correct one under Windows. Again, if you are using windows you can get this information by the phpinfo function.

php -i | grep “Loaded Configuration File”

Once you find the php.ini file that you need to edit, open it up and put the following lines at the end of the file:


Restart Apache. In order to make sure that everything is alright, run:

php -i | grep xdebug

If you see something like:

xdebug xdebug support => enabled
xdebug.auto_trace => 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.idekey => paulus => no value
xdebug.manual_url => =>
xdebug.max_nesting_level => 100 => 100
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_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => /tmp/php_remote.log => /tmp/php_remote.log
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
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

The above command was executed on a Fedora box and by default the xdebug config is located in the /etc/php.d/ directory. Any other possible preference will be dumped as well. The next step is to make sure that eclipse has all the right settings. Open up Eclipse and go to Window->Preferences

Select the Debug under PHP. We have some items that wee need to change:
PHP Debugger should be set to XDebug
PHP Executable
should be set accordingly. (PHP->PHP Executables)

If there is alread a PHP executable defined, then make sure it’s correct. If not, then add one.

I’m using xampp, so I tell eclipse where to find the exe and the ini file. Make sure that you set the debugger to xdebug.

In the main window of Eclipse go to Run->Open Debug Dialog

Here you have two options for PHP. One is a script the other is a Web Page. Double click on PHP Web Page then click on New_configuration. If you want you can certainly name it something else.

After selecting the new debug configuration, there are some settings that need to be set if they haven’t been so already. The first one is Server Debugger. Since we are working with xdebugger, that needs to be set to xdebug. The file we want to debug should be chosen by clicking on the Browse button. Uncheck the Auto Generate check box and change the directory portion of the URL to point to where you want to debug. Usually this portion will be the project directory followed by the path within the project.

That’s it! Away you go! If you have problems debugging. Make sure you aren’t using Alias directories with apache. Sometimes they work and sometimes they don’t. I’m finding that it works a lot better if you don’t use alias directories, especially if you’re using Windows.


Close Menu