PHP的学习--在sublime中使用XDebug(Ubuntu)

王朝学院·作者佚名  2016-05-25
窄屏简体版  字體: 小  |  中  |  大  |  超大  

php的学习--在sublime中使用XDebug(Ubuntu)说起来惭愧,自从开始使用Sublime Text之后,再也没有debug过PHP的代码,最近把debug的环境搭建了一下,在这里记录一下。

安装XDebug

sudo apt-get install php5-xdebug

编辑xdebug.ini文件,添加如下配置

xdebug.remote_enable=1xdebug.remote_handler=dbgpxdebug.remote_host=127.0.0.1xdebug.remote_port=9000xdebug.remote_log="/var/log/xdebug/xdebug.log"

其中参数代表的含义如下:

[Xdebug] ;load xdebug extensionzend_extension_ts = path/tp/xdebug;是否开启自动跟踪xdebug.auto_trace = On;是否开启异常跟踪xdebug.show_exception_trace = On;是否开启远程调试自动启动xdebug.remote_autostart = Off;是否开启远程调试xdebug.remote_enable = On;允许调试的客户端ipxdebug.remote_host=127.0.0.1;远程调试的端口(默认9000);xdebug.remote_port=9000;调试插件dbgpxdebug.remote_handler=dbgp;是否收集变量xdebug.collect_vars = On;是否收集返回值xdebug.collect_return = On;是否收集参数xdebug.collect_params = On;跟踪输出路径xdebug.trace_output_dir="path/to/xdebug/trace";是否开启调试内容xdebug.PRofiler_enable=On;调试输出路径xdebug.profiler_output_dir="path/to/xdebug/profiler"

重启nginx和php

sudo /etc/init.d/nginx restartsudo /etc/init.d/php-fpm restart

然后在Sublime Text使用package control安装xdebug client,用ctrl+shift+p调出搜索框,输入Package Control: 选中其中的Package Control: InstallPackage,输入Xdebug client,找到xdebug client,安装,安装完成后要重启Sublime。其操作如下:

要调试某一个项目,首先得把这个项目在sublime下保存成一个project。

sublime->project->save project as ...

接下来配置项目

sublime->project->edit poject

配置文件类似以下内容:

{ "folders": [ { "follow_symlinks": true, "path": "." } ], "settings": { "xdebug": { "url": "http://my.local.website/", } }}

再在Chrome中安装Chrome Xdebug Helper扩展。在下载和安装Chrome扩展后,你必须重新启动浏览器。重新启动后,你将看到在Chrome的地址栏的新图标:

点击它,将启用/禁用调试。但是,我们首先需要调整扩展中使用Sublime Text 的会话密钥。

在Chrome中Tools > Extensions

打开Xdebug helper options:

开启调试方式也比较简单,在想要加断点的地方右键

xdebug->Add/Remove breakpoint

这样项目在运行到本行的时候就会停止下来

然后开始调试,在菜单栏选择

tools->xdebug->start debugging(launch browser)

sublime会自动打开浏览器,进入配置时写的网站链接,进行调试。

调试中所用的功能可以在调试文件中右键查看之。

快捷键说明如下

Start/Stop debugging sessionStart Debugging -Ctrl+Shift+F9or⌘+Shift+F9Start Debugging (Launch Browser)Restart SessionStop Debugging -Ctrl+Shift+F10or⌘+Shift+F10Stop Debugging (Launch Browser)Stop Debugging (Close Windows)

BreakpointsAdd/Remove Breakpoint -Ctrl+F8or⌘+F8Set Conditional Breakpoint -Shift+F8Clear BreakpointsClear All BreakpointsWatch expressionsSet Watch ExpressionEdit Watch ExpressionRemove Watch ExpressionClear Watch ExpressionsSession commandsEvaluateExecuteStatusContinuation commandsRun -Ctrl+Shift+F5or⌘+Shift+F5Run To LineStep Over -Ctrl+Shift+F6or⌘+Shift+F6Step Into -Ctrl+Shift+F7or⌘+Shift+F7Step Out -Ctrl+Shift+F8or⌘+Shift+F8StopDetachOtherRestore Layout / Close Windows -Ctrl+Shift+F11or⌘+Shift+F11Settings - DefaultSettings - User问题无法跟踪断点这可能是xdebug端口被占用,按Ctrl+`或者菜单栏View->show Console查看错误信息,有可能是xdebug端口已经被占用的缘故。

在sublime xdebug中关闭调试,或者重启sublime可以解决这个问题,如果还不行,可以修改端口号,如xdebug.ini中的端口号修改为为1000,在perferences->package settings->xdebug->setting-user文件中加入如下内容:

{ "port": 10000}

弄好这个还是费了些时间~~

参考Debug PHP with Sublime Text 2 and Xdebug on Ubuntu

用Xdebug和Sublime调试PHP代码

Sublime配置XDebug

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航