TechRepublic : A ZDNet Tech Community

Debug PHP applications with Xdebug and Komodo

Tags: Scripting languages, Vincent Danen, Xdebug, PHP, Komodo, PHP application, IDE, server, Linux Tips Newsletter

  • Save
  • Print
  • Recommend
  • 6

Takeaway: 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!

  • Save
  • Print
  • Recommend
  • 6

Print/View all Posts Comments on this article

Equivalent for Windows? blarman | 05/22/07
Windows solution for EasyPHP christopher.godawski@... | 05/23/07
xdebug in windows vdanen | 05/23/07

What do you think?

White Papers, Webcasts, and Downloads

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET

SmartPlanet

Click Here