phpStorm2021中xdebug3的安装使用
引言:这里记录下花了几个小时才搞定的xdebug的安装和使用,原理不做深究。
主要目的是后续自己如果还需要配置,有得回顾。
1 安装环境
1、macOS Big Sur,版本11.4
2、VMware虚拟机中,宝塔linux免费版 7.0.3(php7.4+nginx1.16.0)
3、phpStorm2021.1.4
4、chrome浏览器版本 91.0.4472.114(正式版本)
2 安装步骤
2.1 在宝塔linux后台,安装xdebug扩展

2.2 在php.ini中配置xdebug
; xdebug3 配置
xdebug.mode=debug ;这个是xdebug3 的新用法
xdebug.log=/tmp/xdebug.log
xdebug.idekey="PHPSTORM"
xdebug.start_with_request=default
xdebug.remote_handler=dbgp
xdebug.client_host=centos7mini ;这里填写ip也行,项目代码所在服务器的ip
xdebug.client_port=9009 ;xdebug3 监听的端口
xdebug.discover_client_host = true ;这个很重要,必须有,不然断点debug不出来,原理不做深究
2.3 phpStorm的配置
2.3.1 phpStorm指定php环境的配置(Preferences->PHP)

1、上面的第4步,配置CLI Interpreter,详细配置如下图:



上图中的SSH Configurations配置页面,第2、3、4步,分别是连接服务器的域名/ip地址、用户名、密码;第6步是验证配置是否成功,成功的配置如下图:

点击“OK”,保存后进入下一步:


点击“OK”,保存后进入下一步:

点击“OK”,保存后,完成CLI Interpreter的配置
2、在phpStorm的php环境配置图的第5步,Path mappings配置

点击“OK”,保存后,完成Path mappings的配置
2.3.2 在phpStorm中配置debug(Preferences->PHP->Debug)


2.3.3 在phpStorm中配置Servers(Preferences->PHP->Servers)

3、验证配置是否成功




最后点击“Validate”,验证是否成功,如下图:


2.3.4 Run/Debug Configurations

3 测试debug功能

4 参考文档来源
1、https://www.cnblogs.com/feimoc/p/14684730.html
2、https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001818099-Validating-debugger-configuration-Specified-URL-is-not-reachable-404-
3、https://www.jetbrains.com/help/phpstorm/run-debug-configuration.html
4、https://readme.im/dev/39#PHPStorm-XDebug-dbgp-client
5、https://xdebug.org/docs/step_debug#discover_client_host
6、https://blog.csdn.net/hfut_wowo/article/details/77488165
7、https://www.cpming.top/p/phpstorm-xdebug-setting
8、https://stackoverflow.com/questions/64878376/xdebug-step-debug-could-not-connect-to-debugging-client