My previous post touched upon the basics of getting Eclipse PDT (PHP Development Tools) up and running for PHP development. In this post, we’ll be looking at getting PHP debugging capabilities into our PHP dev environment. Again, I’ll be focusing on Ubuntu Linux – 8.04 LTS to be specific: however, with minor changes, this can be used on any platform.
Of course, there are simpler methods of debugging PHP scripts: a var_dump is quite handy in terms of simple debugging – however, having the right tools at hand for development means that we can spend more time in actual development than writing debug statements every once in a while – anyways, that’s my take.
XDebug is a remote debugger. Here we’ll take a look at getting XDebug working with Eclipse PDT providing a full debugging client. The first step would of course be to get Eclipse PDT up and running (refer previous post if needed). Once done, the next step would be to get Xdebug for our PHP environment set up – in my case, PHP5. On Ubuntu, this can be achieved by:
apt-get install php5-xdebug
This should install Xdebug for PHP5. Next, we’d configure Xdebug by editing the PHP configuration file. Most systems require the configuration items be added to the main php.ini, or the appropriate conf file. In Ubuntu 8.04 LTS, a separate configuration file,xdebug.ini, is created for Xdebug. Open this file using your favorite text editor (vim in my case):
sudo vim /etc/php5/conf.d/xdebug.ini
Add the following lines after the zend_extension= or zend_extension_ts= conf value.
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
And restart your web-server. In my case, Apache:
/etc/init.d/apache2 restart
To try out the debugger, open a PHP project in Eclipse (if you are importing an existing project via CVS, remember to add it as a PHP project using the New Project Wizard). In Window->Preferences->General->Web Browser, select external web browser, and set it to point to your default web browser. Next go into the debug section, by Window->Preferences->PHP->Debug, and set the PHP Debugger option to XDebug (by default this is set to the Zend Debugger). Note the chekbox “Break at first line” in this page as well – you can change this later on, as required. After you’ve applied your changes, go into the Debug menu, by Run->Open Debug Dialog… Here, make sure the Server Debugger is set to XDebug, and that the PHP server points to http://localhost or an appropriate server location. The file section should point to the file to be debugged, relative to your workspace (Note: if your project is missing from the list, check whether you’re project is configured as a PHP project – I’ve noticed that non-PHP projects fail to appear on this list). Thus if your file is index.php, the relative path maybe something/www/index.php etc.
Next, check the URL section to see whether it points to the correct location – if not, make sure you uncheck the “Auto-Generate” check box, and enter in the correct location. Apply the changes and close the dialog box.
A view of the Debug dialog is here:

You should now be ready to debug your application. Click on Run->Debug or F11 to enable debugging – Eclipse should switch to the Debug View, and the page should start loading in your external browser. If “Break at First Line” checkbox was checked previously, then the program would have “stopped” at the first line – you can step into or step over subsequent lines using the controls on your top left corner. Alternatively, you can place breakpoints at various locations and stop code execution there as well. The variables tab should give you the variables and their values at various times. I good guide from which I borrowed from is here. Get creative – start debugging.
A view of the debugger in operation is here:




Dear,
I’m using Firefox 3.0, Version: 3.3.2 on Ubuntu. After all config, i press F11 to debug. Firefox is opened, it create a new tab with name is Untitled an show download dialog require I download *.php file. And Eclipse doesn’t not with to debug view.
Help me!
Thanks,
Comment by trunghpb — November 14, 2008 @ 3:32 pm |
#trunghpb I’ve got exactly the same problem. Can’t find a solution anywhere. did you have any luck?
Comment by Sky — November 15, 2008 @ 11:53 pm |
I fixed this by reinstaling and pointing window>preferences>Php>php executables to my php5 file rather than php.In my case /usr/bin/php
Comment by Sky — November 16, 2008 @ 4:24 pm |
I’m having the same problema as trunghbp and Sky, but I cannot change that setting, when I try to modify it Eclipse says: “This is a predefined PHP executable configuration which cannot be modified”
Comment by Fran — March 20, 2009 @ 2:46 pm |
Tried this. After trying for a while to get zend going, I came across this post and gave xdebug a shot. Surprisingly easy, I’m glad to finally be able to debug php. You should post this on the Ubuntu help wiki. Thanks dude.
Comment by ricardo — July 2, 2009 @ 2:38 am |
Thanks for the article.
One thing that surprises me is the requirement to configure the Eclipse feature to get to the “file to be debugged”. I have projects with large numbers of files. Am I supposed to create a new configuration for each file I want to debug? Seems incredibly complex to do. Wouldn’t Eclipse be capable of just taking the name of the script I’m clicking on *dynamically* and then apply the debug mechanism to it?
You might not have any involvement in this plugin, and I’m certainly not accusing anyone (just to make sure). I’m just wondering if I’m the only one having this problem and if there is a solution…
Thanks,
Yannick
Comment by ywarnier — July 22, 2009 @ 8:07 pm |
[...] Debugging PHP in Eclipse using XDebug – Eclipse Debugging [...]
Pingback by Xdebug Remote Debugging — August 15, 2009 @ 6:08 am |
Thanks for your help! i’ve been trying to get it working for a long time, but my efforts were fruitless. This guide made it really easy!
Comment by Bram — August 27, 2009 @ 6:31 pm |
I followed your instructions, but my debug go straight on to the end and does not stop at breakpoint…I am on Kubuntu 9.04 but the config file is the same as 8.04…any help please? Two days I am working on it…
Comment by Alex — September 15, 2009 @ 5:04 pm |
sorry, lost subscription…
Comment by Alex — September 15, 2009 @ 5:07 pm |
That worked for me!
Thank you so much
Comment by Faber — October 4, 2009 @ 7:57 am |