Web Development

Debug PHP applications with Xdebug and Komodo

Learn to configure Xdebug and Komodo to work together and provide debugging for PHP applications on your server.

Good developers use good tools and design when writing applications, and the same is true for Web-based applications written in PHP. Two tools that are very valuable for PHP applications are Komodo and Xdebug. Komodo is a cross-platform IDE that can handle debugging remote PHP applications using the DBGp protocol, and Xdebug is an extension for PHP that provides debugging support. Put them together and you are able to remotely debug any PHP applications on your server.

The first step is to install Xdebug on the server where the scripts to be debugged are being run. This can be easily accomplished using PECL. You will need to install the Apache, PHP, and PEAR development files; most Linux distributions provide these as packages, such as apache-devel, php-devel, and perhaps php-pear. With these packages or your distribution's equivalent, execute:

# pecl install xdebug-beta

Some distributions provide packaged Xdebug binaries, so look for that first; if it's not included, you'll need the Apache/PHP development files to build it from source. Once that's done, edit /etc/php.ini or the equivalent and add:

zend_extension=/usr/lib/php/extensions/xdebug.so
 
[debug]
; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
;xdebug.idekey=

Unless you are planning on running the IDE on the same host, change the Xdebug.remote_host keyword from localhost to the hostname of the machine you will be running the IDE on.

With Komodo, make sure that you configure debugging support correctly. Enter Preferences -> Debugger -> Connection and set the port to the port you defined above with xdebug.remote_port (in this case, 9000). Make sure that Debug -> "Listen for remote debugger" is checked.

Configuration is done. If you haven't done so already, restart Apache on the server and then browse to a page on your site. Load the page, but append the XDEBUG_SESSION_START get variable to the URL, for instance:

http://devel.mysite.com/blog/submit.php?XDEBUG_SESSION_START=1

If everything is configured correctly, Komodo should alert you that a remote application has requested the debugging session to start. Select Yes, and you will have a new document open with the code of the page and the debugging session beginning.

If it doesn't work the first time, make sure that the remote server has straight access to the debugger's port on the machine. If there is a firewall in between the IDE and the server, you'll need to make sure the firewall forwards connections on that port to the computer that the IDE is running on.

Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

3 comments
christopher.godawski
christopher.godawski

Hi, I have been using the incredible 3-in-1 PHP solution "EasyPHP" (www.easyphp.org). It contains a fully functional installation containing Apache, MySQL and PHP with an integrated set of development tools. However, I haven't found a way to use an interactive debugger with it. Any idea on how I might integrate any of these tools with it ?

blarman
blarman

Is there an equivalent for Windows-based installs?

Editor's Picks