phpStorm配置vagrant下的xdebug

作者:matrix 发布时间:2017年10月15日 分类:零零星星

测试环境:

服务端:vagrant下ubuntu16的lnmp.org一键安装包
IDE:phpStorm for mac
xdebug扩展进行断点调试

虚拟机安装配置xdebug扩展

连接vagrant ssh

cd ~
wget https://xdebug.org/files/xdebug-2.5.5.tgz
tar -zxvf xdebug-2.5.5.tgz
cd xdebug-2.5.5
/usr/local/php/bin/phpize #用phpize生成configure配置文件
./configure && make && make install

记录下Installing shared extensions的信息用于配置php.ini

2018-11-06 修改更新
尾部添加:

[xDebug]
zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
xdebug.idekey = "PHPSTORM" #需要和ide根据保持抑制
xdebug.default_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9001 #需要和ide根据保持抑制
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler="dbgp"
xdebug.remote_log = /tmp/xdebug.log #日志记录 方便找错

chrome浏览器插件

安装官方推荐扩展 Xdebug helper
https://chrome.google.com/webstore/detail/eadndfjplgieldjbigjakmdgkmoaaaoc

配置插件xdebug helper
图片4182-phpStorm配置vagrant下的xdebug

确保IDE KEY和ini配置保持一致

配置phpStorm

确保Languages & Frameworks =》 PHP =》 Debug 配置端口和xdebug.remote_port一样。
图片4183-phpStorm配置vagrant下的xdebug

DBGP配置一致
图片4183-phpStorm配置vagrant下的xdebug

php -> servers 配置
图片4188-phpStorm配置vagrant下的xdebug

根据自己开发环境修改配置:

Name是Server名称,可以随便填写;
Host是项目的访问地址;
Port为你Web服务器的端口;
还需要配置项目路径的映射(path mapping),将项目的根目录以及public目录映射到Vagrant服务器中的绝对路径。这个需要确保一致

如果maping路径配置有问题 可能会出现 错误:

下午2:53  Debug session was finished without being paused
It may be caused by path mappings misconfiguration or not synchronized local and remote projects.
To figure out the problem check path mappings configuration for 'admin.sp' server at PHP|Servers or enable Break at first line in PHP scripts option (from Run menu).

这样会导致设置的断点无效,每次调试都会进入index.php入口

开始调试

开启xdebug监听 :Run -> Start Listening for PHP Debug Connections 或者点击顶部导航栏的☎️电话图标
图片4189-phpStorm配置vagrant下的xdebug

浏览器插件打开调试
图片4192-phpStorm配置vagrant下的xdebug

浏览器页面请求的网址即可看到调试信息

网页和api调试配置方式本质都是在 cookie 中自动添加XDEBUG_SESSION=phpStorm

调试快捷键

F7 通过当前行,进入下一行,如果该行是方法,则进入方法体
F8 通过当前行,进入下一行,如果该行是方法,也直接进入下一行,不进入方法体
F9 通过整个流程,全部顺序执行

参考:
https://blog.csdn.net/RobotYang123/article/details/80370030
https://www.fanhaobai.com/2017/09/xdebug-in-docker.html

https://segmentfault.com/a/1190000007789295
http://mrcelite.blog.51cto.com/2977858/1903157