如何配置sublime xdebug进行远程调试

  使用sublime xdebug可以进行远程调试,可以使用chrome安装Debug插件,其实也可以直接使用任何浏览器进行访问和远程调试,本人一开始使用了chrome安装Debug插件的方式,后来才发现不用安装也可以直接进行调试。具体步骤如下:

第一步:安装php xdebug扩展

(本人使用宝塔安装,一键搞定)

参考http://www.xdebug.org/docs/install

讲的很详细,这里略过。

 

第二步:安装sublime xdebugclient(不是xdebug)

直接用package control安装即可

第三步:配置php xdebug扩展

windows:

  1. [XDebug]  

  2. zend_extension = "D:xamppphpextphp_xdebug.dll"  #(位置一定要正确)

  3. xdebug.remote_autostart=1  

  4. xdebug.remote_enable = On  

  5. xdebug.remote_host = "xxx.xxx.xxx.xxx" #这里是远程调试,即为你sublime开发机器的ip地址(可以使用路由器将公司的IP请求转发到自己的机器上)  

  6. xdebug.remote_port = 9001 #默认为9000,防止与php-fpm冲突,改为9001(你sublime开发机器防火墙一定要打开这个端口,不然断点无效)

  7. xdebug.remote_handler = "dbgp"  

linux:

文件位置:......./php/56/etc/php.ini或者....../php/72/etc/php.ini具体要看PHP的版本

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = xxx.xxx.xxx.xxx #这里是远程调试,即为你sublime开发机器的ip地址(可以使用路由器将公司的IP请求转发到自己的机器上) 
xdebug.idekey="sublime.xdebug"
xdebug.remote_handler = "dbgp"
xdebug.remote_req = req
xdebug.remote_port = 9001 #默认为9000,防止与php-fpm冲突,改为9001(你sublime开发机器防火墙一定要打开这个端口,不然断点无效)
xdebug.remote_connect_back = 1
xdebug.auto_trace = 1
xdebug.collect_includes = 1
xdebug.collect_params = 1
xdebug.collect_vars = on
xdebug.show_local_vars = 1
xdebug.remote_log = /tmp/xdebug.log
zend_extension=/www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so #(位置一定要正确)

如下图:

 

第四步:配置sublime xdebug

用sublime打开你要调试的程序,点击sublime导航的Project->save project as。生成一个.sublime-project的文件,修改其为:

本地调试配置

  1. {  

  2.     "folders":  

  3.     [  

  4.         {  

  5.             "path": "/D/xampp/htdocs"  #这里应该会自动生成  

  6.         }  

  7.     ],  

  8.     "settings":  

  9.     {  

  10.         "xdebug": {  

  11.             "path_mapping": {  

  12.             },   #本机调试此项不需要设置  

  13.             "url": "http://localhost/xampp/php.php",#这里为xdebug打开的页面  

  14.             "super_globals": true,  

  15.             "close_on_stop": true,  

  16.             "port": 9001   #此port与之前xdebug扩展一致  

  17.         }  

  18.     }  

  19. }  

远程调试配置

  1. {  

  2.     "folders":  

  3.     [  

  4.         {  

  5.             "path": "/D/biwebs"  

  6.         }  

  7.     ],  

  8.     "settings":  

  9.     {  

  10.         "xdebug": {  

  11.             "path_mapping": {  

  12.                 "/data/web/dataoa/" : "D:/biwebs/dataoa/"  #与本地就此处不同,必须将远程与本地的映射写明  

  13.             },  

  14.             "url": "http://testdata.zhenai.com/test.php",  

  15.             "super_globals": true,  

  16.             "close_on_stop": true,  

  17.             "port": 9001  

  18.         }  

  19.     }  

  20. }  

下面来看下效果:

(本地)

1.先在试例代码中标记个断点(ctrl+F8)


2、开启xdebug,打开浏览器,或者其他工具访问站点开始进行调试(不只是chrome哦,任何浏览器都可以)

3、调试代码

 一些常用快捷键

Shift+f8: 打开调试面板
f8:打开调试面板快速连接
Ctrl+f8: 切换断点
Ctrl+Shift+f5: 运行到下一个断点
Ctrl+Shift+f6: 单步
Ctrl+Shift+f7: 步入
Ctrl+Shift+f8: 步出

变量一目了然展示在眼前。

具体其它操作见https://github.com/martomo/SublimeTextXdebug

远程也是如此,前提是两台机器必须是互通的。调不通多点耐心,相信胜利就在眼前!

如果遇到不能跳转到断点的问题,可能是本地(你IDE所在的机器)的端口没有开放(本人使用的是9001),也可能是服务器端口被占用(需要重新启动并加载PHP再试)

原文地址:https://www.cnblogs.com/gougou1981/p/14231274.html