Drupal Testing With Xdebug and Eclipse

I had so much trouble getting Xdebug and Eclipse working together that I had to make some notes here to reference in the future. I got so carried away with this quest that I got it running with both Xampp on my desktop PC and with Quickstart.

Warning to self: Make sure to have only one PHP IDE running at a time when running Xdebug. Had phpDesigner 7 running minimized and wasted a lot of time trying to figure out why Eclipse wasn't working with Xdebug.


  • Eclipse -- Version: Helios Service Release 2
  • PDT -- PHP Development Tools 2.2.1
  • Xdebug -- php_xdebug-2.1.1-5.3-vc6.dll This is downloaded from xdebug.com to match my version of PHP which is 5.3.5 on this Xampp install.
  • Xampp -- version 1.7.4 which has Apache 2.2.17
  • Firefox 5.0 with "easy Xdebug 1.5" Add-on.

These tools are all well known and documented on their respective web sites as to download and installation.

Web Resources Used To Get Xdebug Working.

  • Creating virtual hosts in XAMPP. Don't forget to configure your hosts file in Windows. C:\WINDOWS\system32\drivers\etc\hosts for my XP.
  • Configuring Eclipse
  • Very helpful was an article by Nathan A. Good on the IBM website. The example files used here where linked to for download on page 2 of the article.
  • PHP remote debugging with Xdebug and Eclipse PDT: Blog post by Bogdan Albei. This is a source for configuring Xdebug in your php.ini file. This part of the setup is well documented in many places on the internet. Here is the extra meat from the blog post:

    From Bogdan Albei's blog: Now the tricky part, Eclipse has to be configured to accept debugging sessions from XDebug. Follow the steps below: Open your project in Eclipse PDT In the main menu select Project->Properties On the left side of the window select "PHP Debug" and then click on "Configure Workspace Settings" On the "PHP Debugger" dropdown select Xdebug and click "Apply" Click "Configure" to the right of Xdebug in the same window. Select Xdebug and click "Configure". On the "Accept remote session(JIT)" select "any" and click "OK". This is extremely important and this is where most people get stuck. That's it, Eclipse is now configured, now all we need is to be able to be in control of our debugging sessions. For this we will need to install a Firefox extension called "easy Xdebug"(yes Firefox, you're not developing PHP in IE are you?).

Remember that we are interested in remote debugging here so look for words like "remote" and "web application" when going over documentation. First go through the virtual hosts link. Your XAMPP install will have a web root in /htdocs that is accessed with a browser at http ://localhost. We want to be able to debug in several locations so as to keep our projects and their files in nice order.

Edit C:\xampp\apache\conf\extra\httpd-vhosts.conf to create another "virtual server". The file comes all commented out and unused. The result is that the files can be anywhere on the computer and are served up just like the ones you put in /htdocs. Here is the part of my httpd-vhosts.conf that matters:

  1. ##Do this only once<br />
  2. NameVirtualHost

  1. &lt;VirtualHost;<br />DocumentRoot C:/xampp/htdocs/<br />
  2. ServerName localhost <br />
  3. &lt;/VirtualHost&gt;

  1. ##Do this for each virtual site<br />
  2. &lt;VirtualHost debug.local&gt;<br />
  3.   DocumentRoot "C:\Documents and Settings\John\My Documents\Axampp\debug_local"<br />
  4.   ServerName debug.local<br />
  5.   ServerAlias debug.local

  1.   CustomLog "C:\Documents and Settings\John\My Documents\Axampp\debug_local\logs\logs" combined<br />
  2.   ErrorLog "C:\Documents and Settings\John\My Documents\Axampp\debug_local\logs\logs"

  1.   &lt;Directory "C:\Documents and Settings\John\My Documents\Axampp\debug_local"&gt;<br />
  2.     Options Indexes FollowSymLinks<br />
  3.     AllowOverride All<br />
  4.     Order allow,deny<br />
  5.     Allow from all<br />
  6.   &lt;/Directory&gt;<br />
  7. &lt;/VirtualHost&gt;

The above will give a server at http ://debug.local with the files at C:\Documents and Settings\John\My Documents\Axampp\debug_local. Think of /debug_local as the same as /htdocs in the original XAMPP install.

Don't forget to configure your Windows hosts file and create your /logs/ directory.

Configure Servers in Eclipse PHP Debug

First set up a PHP Server configuration for each of the virtual servers in Apache that we plan to use. This is how the configuration page will look in Eclipse.


Next click New to add a PHP Server, but in my case I click Edit to show the configuration form.edit_server.png

I was able to leave the Path Mapping blank but some things I read indicate that sometimes you may have to add them.


Eclipse Project Configuration

Create a project using the files in the root of one of your server setups. One set of files is all you need, but it will act like two sets. In this case the project name is DebugTest. If you open it in the PHP presentation you should be able to right click on the project and get it's properties which should look like this:


Eclipse Debug Configurations

This needs to be done for each project. The first screen image should show the best way to bring up the debug configuration screen while in the Eclipse PHP Perspective. The only problem is the context menu disappears during the screen capture. Look at the little green bug under the Window menu, and click on the little triangle that brings the drop down menu.


Here is what you get when you click on Debug Configurations in the above:


Advance and Common tabs were not used, and Auto Generate for the URL was used. As the above image shows we are now configured to debug a "PHP Web Page" with XDebug on the PHP Server named "debug_local". Our starting point project file is at /DebugTest/webDebugExample/enterGreeting.php and we will "Break at the First Line".

Debugging a Remote Project with Xdebug

  • Open in Eclipse the project that is configured as above to work with Xdebug using the PHP Perspective.
  • View the file in Firefox where you want to begin the Xdebug session and click the easy Xdebug add-on to start the session.
  • Now Eclipse asks you if you can move to the PHP Debug Perspective and you indicate yes,
  • Firefox will now be in a waiting mode and look like it is connecting. It will be like that as long as you are running Xdebug through Eclipse.
  • Step through the code using the tools in Eclipse until action is required in Firefox to move to another file. In my case I started with enterGreeting.php and had to click Submit on the page in Firefox to get Eclipse to start on the next file which was results.php.
  • Stepping through results.php then at some point opens GreetMaster2000.php in Eclipse.
  • See the resources links near the beginning to see which files I'm referring to here. They were downloaded via the Nathan Good article.