Debug PHP applications with Xdebug and Komodo

原文:http://articles.techrepublic.com.com/5100-1035_11-6184573.html

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. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值