·您现在的位置: 江北区云翼计算机软件开发服务部 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> PHP的学习--在sublime中使用XDebug(Ubuntu)

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

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
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 session
  • Start Debugging -Ctrl+Shift+F9or⌘+Shift+F9
  • Start Debugging (Launch Browser)
  • Restart Session
  • Stop Debugging -Ctrl+Shift+F10or⌘+Shift+F10
  • Stop Debugging (Launch Browser)
  • Stop Debugging (Close Windows)
Breakpoints
  • Add/Remove Breakpoint -Ctrl+F8or⌘+F8
  • Set Conditional Breakpoint -Shift+F8
  • Clear Breakpoints
  • Clear All Breakpoints
Watch expressions
  • Set Watch Expression
  • Edit Watch Expression
  • Remove Watch Expression
  • Clear Watch Expressions
Session commands
  • Evaluate
  • Execute
  • Status
Continuation commands
  • Run -Ctrl+Shift+F5or⌘+Shift+F5
  • Run To Line
  • Step Over -Ctrl+Shift+F6or⌘+Shift+F6
  • Step Into -Ctrl+Shift+F7or⌘+Shift+F7
  • Step Out -Ctrl+Shift+F8or⌘+Shift+F8
  • Stop
  • Detach
Other
  • Restore Layout / Close Windows -Ctrl+Shift+F11or⌘+Shift+F11
  • Settings - Default
  • Settings - 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