Top Infobar Text

Close Icon
Contact Info     (919) 701-9304

PHP Debugging in Eclipse

The next milestone of the chart project will require some analysis and manipulation of data sets. Seeing as how I am new to PHP, my intuition tells me that the better part of judgment is not to fly blindly into it …

Unfortunately, setting up Eclipse to debug PHP code in a reasonable manner is nearly as complex. I had been using XAMPPlite for development up until this point. I was using version 1.7.3 which uses PHP 5.3.1. In order to debug in eclipse I had to go out seeking a debug binary here. After a long bit of trial and error I found that this binary was no longer supported. So here’s the short step by step:

  1. Download Eclipse IDE for Java EE Developers
  2. Start Eclipse → Help → Install new software
  3. Work with all available sites, search for ‘PHP’ecSnipNote that the PDT can show up multiple times but you only need to select one, click next, install it.
  4. Now go to download the version of XAMPP appropriate for you. I found that the installer worked great.
    1. The default installation instructions worked perfectly for me
    2. If you are trying to install WordPress on top of this, then I think that this tutorial might be useful
    3. I needed to migrate from my XAMPPlite install to my new XAMPP installation.
      1. Copy C:\xampplite\htdocs\YOURSITE to C:\xamp\htdocs\YOURSITE
      2. Copy C:\xampplite\mysql\data\wordpress to C:\xampp\mysql\data\wordpress
        1. Note that this will also be useful for copying in databases for other reasons!!!

You should have XAMPP running a live copy of WordPress for you at this point. The next step is to configure the debugger.

  1. Go to XDebug and download the appropriate version for you. With XAMPP 1.8.1 this corresponds to PHP version 5.4.7 and XDebug 2.2.1.
    1. Your XAMPP installation may come with the latest executable. But to be sure, install this one into C:\xampp\php\ext\
  2. Open C:\xampp\php\php.ini and find the [Xdebug] section.
    1. Edit it to look like this:
      zend_extension = “C:\xampp\php\ext\php_xdebug-2.2.1-5.4-vc9.dll”

      xdebug.profiler_append = 0
      xdebug.profiler_enable = On
      xdebug.profiler_enable_trigger = 0
      xdebug.profiler_output_dir = “C:\xampp\tmp”
      xdebug.profiler_output_name = “cachegrind.out.%t-%s”
      xdebug.remote_enable = 1
      xdebug.remote_handler = “dbgp”
      xdebug.remote_host = “”
      xdebug.trace_output_dir = “C:\xampp\tmp”

    2. Where your zend_extension obviously corresponds to the file you just downloaded.
  3. Restart the Apache service through the XAMPP control panel. (Now would be a good time to verify that xdebug is loaded properly by browsing to http://localhost and clicking on phpinfo(). xdebug is loaded properly if you see a section detailing xdebug configuration parameters).
  4. Load your WordPress install into Eclipse as described in this guide
  5. Right-click on your project in the Project Explorer in Eclipse → Debug As → Debug Configurations
  6. Double click on PHP Web Application to create a new debug configuration
  7. Set the server debugger to Xdebug, Create a PHP Server as follows:
    1. The server settings should look like this:editServer
    2. Click Path Mapping and modify as follows:serverPath
  8. I choose to disable break at first line and to auto-generate debug URLs. Of course you need to modify these instructions to suit your own site, but my final configuration looks like this:debugConfig
  9. Click Apply and debug
  10. If all went well then you should now be looking at a prompt to switch to the debugging perspective and then this:lab304Debug

There are lots of moving parts here, so don’t feel bad if you don’t get it working on your first try. Most errors lie in the following areas:

  1. WordPress database permissions. If you can’t get this working properly, do a fresh install of wordpress and delete the previous entries into MySQL.
  2. PHP configuration. Specifically php.ini — the configuration inputs for this file have changed quite a bit over the past few versions. I can vouch for the configuration / version above.
  3. XDebug version. There are many different versions of this dll binary. Again, I can vouch for the one above but in case you think yours may not be working. A quick way to check to see if it is being loaded by Apache is to go to http://localhost and click phpinfo(). You should see a table for xdebug if it is loaded properly.

Now that I can trace data structures to and from my scripts, I can verify that data is being pulled from the DB and plotted correctly.



4 Responses on “PHP Debugging in Eclipse

  1. Sergi Arias says:

    Thank you for your tutorial!

    I have been looking for an up-to-date tutorial of Eclipse and Xdebug, and this is the only one I could find.

    Anyway, what I find missing here is that the debugger shows the web layout (Browser Output and Debug Output) while stepping on the code. And it only shows it when it ends.

    I’ve been researching why this happen and my conclusion is that it works OK until XAMPP version 1.7.4 and Xdebug with VC6, and next version doesn’t work OK regarding this aspect.

    I think it’s an important feature every PHP debugger must have but as I am not a qualified programmer I’m unable to find a solution.

    Anyway it would be interesting an update to this tutorial that solves this problem.

    Thank you!!!

  2. drmoore says:

    Thanks for the comment Sergi!

    There are MANY different configurations for XAMPP and Xdebug. I had quite a bit of trouble finding a setup that worked for me which is why I wrote up this post.

    If I recall correctly, there is a version of XAMPP (which you may have found is > 1.7.4) that requires using VC9. In the post above I used XAMPP 1.8.1 with the Zend debugger DLL at VC9. Try that one and see if it solves that issue.

  3. Sergi Arias says:

    Thanks for your quick answer!

    It really doesn’t work after XAMPP 1.7.4 even using VC9 or the last version of Xdebug. If you look your last screenshot I can see that “Debug Output” is empty, which shouldn’t be.

    But… Good news! After looking thousands of web pages I discovered what the solution is, and is using in php.ini:
    implicit_flush = on
    output_buffering = 0

    I don’t really understand why until 1.7.3 it works without having to add this lines, and after it requires it, but anyway I think is much easier to debug having the output of what is being executed than just to guess it.

    Hope it helps and thank you again!

  4. drmoore says:

    Thanks for posting the solution!

    I looked at my php.ini file and found that implicit_flush = on, but output_buffering = 4096 with the following comment:

    ; Output buffering is a mechanism for controlling how much output data
    ; (excluding headers and cookies) PHP should keep internally before pushing that
    ; data to the client. If your application's output exceeds this setting, PHP
    ; will send that data in chunks of roughly the size you specify.
    ; Turning on this setting and managing its maximum buffer size can yield some
    ; interesting side-effects depending on your application and web server.
    ; You may be able to send headers and cookies after you've already sent output
    ; through print or echo. You also may see performance benefits if your server is
    ; emitting less packets due to buffered output versus PHP streaming the output
    ; as it gets it. On production servers, 4096 bytes is a good setting for performance
    ; reasons.
    ; Note: Output buffering can also be controlled via Output Buffering Control
    ; functions.
    ; Possible Values:
    ; On = Enabled and buffer is unlimited. (Use with caution)
    ; Off = Disabled
    ; Integer = Enables the buffer and sets its maximum size in bytes.
    ; Note: This directive is hardcoded to Off for the CLI SAPI
    ; Default Value: Off
    ; Development Value: 4096
    ; Production Value: 4096
    output_buffering = 4096

    So it looks like your solution is absolutely correct. It won’t flush the buffer until 4096 bytes have accumulated. Thanks again for pointing it out!

Leave a Reply

Your email address will not be published. Required fields are marked *

Share This