*/ ?>

Fixing Xdebug on Ubuntu 10.04

I was noticing that my variables pane in Netbeans wasn't updating all the time with the right information.  Some files would update the information, but others just wouldn't update.  Turns out that what I needed to do was re-install Xdebug from source, here's how I did it and the links I followed.

To begin with, I had installed Xdebug from the Synaptic package manager, which is supposedly the 'correct' way to do things.  To do this I just went to System >> Administration >> Synaptic Package Manager and searched for xdebug.  This brought up php5-xdebug as the only available option, so I just went ahead and installed it.  The version was listed as 2.0.5-1ubuntu1.  Everything seemed to be working OK when I first installed it, but I didn't actually do much work with the debugger, so I can't confirm that it actually was 100% working.  I also know that over the course of the last month or two that I've been running Ubuntu 10.04 I know that there have been a couple of updates to php and apache, so it's possible that the incompatibility came along at some point since I first set everything up.

So first off I went doing some digging and found this forum post on installng xdebug, but it looked like it was pretty old and perhaps not relevant any more.  It was also saying to use the package manager, which was apparently added after the forum post started.  I didn't even bother going to the second page of posts, though I know that I've used Pear to install xdebug on Fedora with no problems.  Looking at it now, it seems as if there are updated questions for 10.04 on the second page, and it could have just been that I needed to add html_errors = On to my php.ini

Still, since I wasn't feeling like the info here was actually good, I did some more searching, and found this page on the Netbeans wiki.  They have step-by-step instructions for Ubuntu on this page, as well.

One thing that I thought was telling from the page was this:

Many xDebug problems seem to come from tiny mismatches between the exact PHP release you use, and the exact version of xDebug you use. If you simply downloaded the latest version xdebug, or if you got xdebug off a repository, this is probably part of your problem.

They're saying here to go to this page on the Xdebug site that allows you to paste in the output of phpinfo() into a box and get detailed information about exactly which version you need for your environment.  It will even give you installation instructions and a link to the tarball that you need in order to make your own extension.  My instructions looked like this:

Tailored Installation Instructions

Summary

  • Xdebug installed: no
  • Server API: Apache 2.0 Handler
  • Windows: no
  • Zend Server: no
  • PHP Version: 5.3.2-1
  • Zend API nr: 220090626
  • PHP API nr: 20090626
  • Debug Build: no
  • Thread Safe Build: no
  • Configuration File Path: /etc/php5/apache2
  • Configuration File: /etc/php5/apache2/php.ini
  • Extensions directory: /usr/lib/php5/20090626

Instructions

  1. Download xdebug-2.1.0.tgz
  2. Unpack the downloaded file with tar -xvzf xdebug-2.1.0.tgz
  3. Run: cd xdebug-2.1.0
  4. Run: phpize

    As part of its output it should show:

    Configuring for:
    ...
    Zend Module Api No: 20090626
    Zend Extension Api No: 220090626

    If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.

  5. Run: ./configure
  6. Run: make
  7. Run: cp modules/xdebug.so /usr/lib/php5/20090626
  8. Edit /etc/php5/apache2/php.ini and add the line
    zend_extension = /usr/lib/php5/20090626/xdebug.so
  9. Restart the webserver

If you like Xdebug, and thinks it saves you time and money, please have a look at the donation page.

I was able to make it up to line 4 and then realized that I didn't have 'phpize' installed on my system.  So, more googling and I found another Ubuntu Forums page that had the same problem.  Turns out, I didn't have the development libraries installed.  I had also found that I didn't have the php command line interface installed, either.  I was going to just use the cli for the phpinfo() so I went back to synaptic and searched for php-cli and php-dev.  This brought up the php5-dev and php5-cli libraries which I then installed.  After this I was able to get past step 4 and actually build the module.

I used the instructions from the xdebug site for running the configure command, and I notice now that I'm writing this that it's different than what they have on the Netbeans wiki page. The instructions from Xdebug say to just run ./configure but on the wiki page they say to run./configure --enable-xdebug.  I don't know that this makes a difference because it worked for me, but people following this how-to might want to check that they use the --enable-xdebug flag.

I copied my xdebug.so file to my actual user library, so the information that I need to load looks like this:

[xdebug]
zend_extension = /usr/lib/php5/20090626/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000

I did try put these configurations in this file:

/etc/php5/conf.d/xdebug.ini

What this does is allow me to keep upgrading php without worrying about losing my Xdebug settings.  I had to do this as root, so

sudo nano /etc/php5/apache2/conf.d/xdebug.ini

That's really all the more there is to it.  After a restart of the sever xdebug is loaded when I look at the output of phpinfo(), and when I run the debugger from Netbeans, it works with every file, so that I can see all the local variables.  It's pretty nice to have it all working, and it really wasn't much to set up.  Honestly, it was more time trying to verify that it was broken (I did some tests with different files, moving around breakpoints, etc) and then doing the searching to make sure that I had the correct instructions. 

Hopefully this helps someone else with the same problem.  I don't know many other people actually would have this same problem, but I'm pretty sure there are at least a couple people that will find it useful.

blog comments powered by Disqus