Changing Mailman Python Scripts for Virtual Host Support
Using Multi-Byte Character Sets in PHP (Unicode, UTF-8, etc)
Installing Xdebug for use with Eclipse or Netbeans on Linux
Book Review: How to Implement Design Patterns in PHP
Getting Set up with Ogre 3D on Ubuntu
ENUMs, User Preferences, and the MySQL SET Datatype

Installing Xdebug for use with Eclipse or Netbeans on Linux

Tuesday, 4 January 11, 11:48 am
There are 2 recommended ways of installing xdebug: with your system's package manager, or via PECL.

Installing via Package Manager

If your distro includes Xdebug in the package repositories, this is probably the easiest way to install it and keep it up to date. For Ubuntu:
sudo apt-get install php5-xdebug
For Arch:
sudo pacman -S xdebug
This will install into the default location for PHP extensions ie /usr/lib/php/modules/. You will need to enable the module by adding the following line to your php.ini if it's not already there:
zend_extension=xdebug.so

Installing via PECL

PECL is a part of PEAR, so install that first:
sudo apt-get install php-pear
PECL also requires the PHP development libraries, which have to be installed separately on Ubuntu. On many distros, such as Arch Linux, you can skip this step.
sudo apt-get install php5-dev
Now you're ready to get Xdebug:
sudo pecl install xdebug
This will download and compile the Xdebug module. When it finishes successfully, it will tell you where the xdebug.so module was installed, which is fine, but it also tells you to to add a line in php.ini to enable the extension. This last part is automatically output by PECL whenever it's finished compiling a module, and in this case, it's not quite right: Xdebug must actually be loaded as a Zend extension not a regular one.

To do this, you must add the following line to php.ini:
zend_extension="/path/to/xdebug.so"
Use the path that PECL gave when it had finished compiling xdebug, which will be something like this:
zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so

Configuring Line-by-line Debugging

In order to enable debugging features such as stepping through code from your IDE, you'll need to configure Xdebug for remote sessions. Create the following section in the 'Module Settings' section within php.ini:
[xdebug] xdebug.remote_enable=on xdebug.remote_handler=dbgp xdebug.remote_port=9000
Note that these settings assume you'll be debugging on the local machine, i.e. any address that resolves to 127.0.0.1 e.g. localhost. If you want to debug on another machine, specify it with the following additional line:
xdebug.remote_host=MACHINENAME
Check this page for a list of all of the Xdebug options that you can set in php.ini. Another thing you might want to get at this point is the 'easy Xdebug' Firefox extension as it allows you to enable and disable debug sessions from your browser (rather than just from your IDE).

Now restart your web server so that php.ini is reloaded. You can check it's installed correctly by looking for it in the output of phpinfo() as in the screenshot below.

Configure the IDE

Now we just need to make sure our IDE is set up to accept connections from Xdebug. The exact steps to follow will depend on the IDE you use.

Netbeans

Netbeans should already be set up correctly:



Start the debugger with the Debug Project button on the toolbar:

Eclipse

Go to Window > Preferences, and select the Debug section within the PHP options (don't get confused with the separate Run/Debug options which we don't need to worry about here). Now select XDebug as your debugger. If you aren't using localhost for your development server, you can change that also. Leave the PHP Executable as it is, and click OK:



You can now start a debugging session from within Eclipse by right-clicking on a page, and choosing Debug As > PHP Web Page.

Please enter your comment in the box below. Comments will be moderated before going live. Thanks for your feedback!

Cancel Post

/xkcd/ Demons