在NotePad++中安装DBGP debugger调试PHP程序
本文章涵盖了[url=http://notepad-plus.sourceforge.net/]NotePad++[/url]的安装、[url=http://xdebug.org/]Xdebug[/url]的安装、[url=http://notepad-plus.sourceforge.net/uk/site.htm]DBGP插件[/url]的安装以及简单的调试[url=http://www.php.net/]Php[/url]的示例。[b]DBGP插件(PlugIn)如何工作[/b]1、Web浏览器(例如:[url=http://www.mozillaonline.com/]FireFox[/url])通过Http端口(80)请求Url来访问[url=http://httpd.apache.org/]Apache[/url] Server。2、[url=http://xdebug.org/]XDebug[/url]是Apache的一个扩展(DLL In Windows),类似于GD库。3、[url=http://xdebug.org/]XDebug[/url]是Web Server(Apache)与远程调试客户端(例如:NotePad++的[url=http://notepad-plus.sourceforge.net/uk/site.htm]DBGP插件[/url])的一个接口,他们之间通过9000端口通信。Wire Flow:[b]Web browser[/b] <==> [b]Port 80[/b] <==> [b][url=http://httpd.apache.org/]Apache[/url] + [url=http://www.php.net/]PHP[/url] + [url=http://www.xdebug.com/]Xdebug[/url] extension[/b] <==> [b]Port 9000[/b] <==> [b]DBGp Plugin-notepad++[/b]1、开启NotePad++,BDGP插件打开9000端口。2、Web browser向[url=http://httpd.apache.org/]Apache[/url]请求一个php页面,请求的Url中包含一个指定的参数(即:XDEBUG_SESSION_START)以便激活远程调试。3、[url=http://www.apache.org/]Apache[/url]调用[url=http://www.php.net/]Php[/url]解释器(Interpreter)。4、Php解释器加载[url=http://www.xdebug.com/]XDebug[/url]模块。5、[url=http://www.xdebug.com/]XDebug[/url]模块检测到第2步发送的XDEBUG_SESSION_START参数,开启远程调试。6、[url=http://www.xdebug.com/]XDebug[/url]连接到远程调试客户端(依赖于[url=http://www.xdebug.com/]XDebug[/url]的配置项,在php.ini中)。7、[url=http://www.xdebug.com/]XDebug[/url]和调试客户端建立连接以后,通过9000端口进行对话。8、当调试客户端向[url=http://www.xdebug.com/]XDebug[/url]发送执行Php语句的指令后,[url=http://www.php.net/]Php[/url]解释器执行Php语句,相应的输出由Apache通过80端口发送出去到Web Browser。9、当所有的php代码执行完后,[url=http://www.xdebug.com/]XDebug[/url]断开与调试客户端的连接。10、[url=http://httpd.apache.org/]Apache[/url]断开与Web Browser的Http连接。[b]安装步骤[/b]首先,你先安装好Apache和Php的运行环境,这个我就不说了,不会安装的话,[url=http://tech.163.com/06/0206/11/299AMBLT0009159K.html]看这里[/url],也可以跟我一样,使用[url=http://www.apachefriends.org/zh_cn/xampp.html]xampp[/url],还有[url=http://sourceforge.net/projects/winlamp/]WinLamp[/url]也推荐一下,反正是开发环境,不是生产环境。我用的xampp,php模块安装在c:\xampp\php目录下(这个因人而异)。1、安装NotePad++,注意,不要选择exe安装包,选择[url=http://sourceforge.net/project/showfiles.php?group_id=95717&package_id=102072]zip[/url]包,使用包中的ansi版本即可(新建一个文件夹notepad++到c:\Program Files,将ansi下面的所有文件拷贝进去),否则在你安装DBGP插件的时候会[url=http://www.visualguides.org/notepad-gives-the-error-this-ansi-plugin-is-not-compatible-with-your-unicode-notepad/]报错[/url](This ANSI plugin is not compatible with your UnicodeNotepad++)。[img=488,175]http://www.haoguoliang.com/blog/2009/03/19/notepad%2B%2B.jpg[/img]2、下载[url=http://notepad-plus.sourceforge.net/tw/site.htm]NotePad++[/url]的中文[url=http://notepad-plus.sourceforge.net/commun/nativeLanguageFiles/chineseSimplified.xml]xml文件[/url],将其重新命名为nativeLang.xml,放到notepad++的根目录下(c:\Program Files\notepad++)。3、下载[url=http://notepad-plus.sourceforge.net/uk/site.htm]DBGP插件[/url],一个Zipped文件,解压以后,将dbgpPlugin.dll和Readme.txt文件复制到Notepad++的plugins目录下(c:\Program Files\notepad++\plugins)。4、创建一个php文件phpinfo.php,打印php的配置信息。5、新建一文件夹supplier到apache的htdocs目录下,执行phpinfo.php,即:http://localhost/supplier/phpinfo.php 检查你的php版本,我的php版本是5.1.4,确认你的php.ini文件的位置,以及php扩展库extensions文件夹的路径。比如:[img=640,331]http://www.haoguoliang.com/blog/2009/03/19/PhpInfo.JPG[/img]图中表明:php.ini文件在[b]C:\WebServer\Apache2\modules\php\[/b]文件夹下扩展库的路径是[b]C:\WebServer\Apache2\modules\php\ext\[/b]6、到XDebug的[url=http://www.xdebug.org/]官方网站[/url]上下载XDebug For Php的Module,注意要与你的php的版本相匹配,对我来说,就是 [b]PHP 5.1.2 - 5.1.6[/b],对应的扩展库为[b]php_xdebug-2.0.0-5.1.6.dll[/b][img=384,480]http://www.haoguoliang.com/blog/2009/03/19/Xdebug.JPG[/img]7、拷贝[b]php_xdebug-2.0.0-5.1.6.dll[/b]文件到你的php扩展库文件夹,比如:[b]C:\WebServer\Apache2\modules\php\ext\[/b] (php.ini中的[b]extension_dir[/b]项)8、用Windows记事本软件打开php.ini,增加下面的几行到php.ini的最后[xdebug]zend_extension_ts="C:/WebServer/Apache2/modules/php/ext/php_xdebug-2.0.0-5.1.6.dll"xdebug.remote_enable=1xdebug.remote_handler=dbgpxdebug.remote_host=127.0.0.1xdebug.remote_mode=reqxdebug.idekey=defaultxdebug.remote_log="D:/www/ourcommunity.dev/log/xdebug.log"xdebug.remote_port=9000xdebug.show_exception_trace=0xdebug.show_local_vars=9xdebug.show_mem_delta=0xdebug.trace_format=0根据你自己的情况设置zend_extension_ts和xdebug.remote_log两项。9、重新启动apache,如果apache启动失败,试着将php.ini中关于zend的配置项注释掉。比如:;zend_extension_manager.optimizer_ts = "C:\xampp\php\zendOptimizer\lib\Optimizer"10、重新执行phpinfo.php文件,有没有看到其中的xdebug区域?[img=640,210]http://www.haoguoliang.com/blog/2009/03/19/PhpInfo_Xdebug.JPG[/img][b]配置Notepad++[/b]1、打开Notepad++,进入插件菜单,弹出DbGp下拉菜单列表。[img=399,480]http://www.haoguoliang.com/blog/DBGp_Plugin.JPG[/img]2、点击"[b]Config...[/b]"菜单项,如下图一样配置DbGp调试器(Remote Path 和 Local Path是你的php文件所在的文件夹)[img=500,359]http://www.haoguoliang.com/blog/DBGp_Config.JPG[/img][b]简单示例[/b]未完待续......