PDT and Xdebug

PHP is a good language for web development, but having to enter in print statements whenever you need to know what's going on inside your script can be very tiresome. It's much better to have a good IDE that supports debugging, but there's a lot of choices, a lot of places you can slip up, and the easiest option is too expensive for those of us who aren't students.

(Updated 14/4/09) This article was first written about and Eclipse PDT, and was mostly about how ridiculously difficult they were to get working together. Since then I tried Xdebug, an open-source alternative to, and found it much easier to set up, so this article is about setting up Eclipse PDT with Xdebug.


If you're having problems try and replicate my environment below as accurately as possible before setting debugging up, then once it's working try and alter parts one at a time until it works the way you want.

Server-side setup

Install xdebug, then add the following to your /usr/local/etc/php.ini :

Client-side setup

A test project, prints "Hello World"

Go to Window>Preferences. Set the global debugging settings which apply to all projects.

Go to Run>Debug configurations, create a new PHP Web Page debug configuration, and set it up with the project specific settings.

Now for the moment of truth; testing if a breakpoint is caught when the debug configuration is run.

Running the debugger in a different project; variables, the stack, breakpoints and watches can be interacted with to make debugging easier.

This is very useful, and really decreases the time you spend tracking down bugs by putting print statements everywhere. Now if a variable has a strange value in it you can simply set a watch on it, and find out the exact point at which the variable goes wrong, without any tedious print statements or guesswork.