如何将PhpStorm与Xdebug连接

3
我希望有人能够帮助我解决我的问题:
我最近开始了我的第一个PHP项目,需要设置调试。我知道许多人在我之前遇到了同样的问题,但我很难找到解决方案。
我需要使用Xdebug设置PhpStorm,并进行所有设置,但仍然无法工作。当我启动调试会话时,我卡在这里,没有更多的信息:

enter image description here

这是我的项目设置:
带有Xdebug的 Docker Webapp:0.0.0.0:80->80/tcp,0.0.0.0:443->443/tcp PhpStorm PHP调试设置:

enter image description here enter image description here enter image description here

Xdebug设置来自phpinfo()

enter image description here

听取PhpStorm的调试连接是开启的,启动调试会话通过GET方式创建一个会话:https://localhost/?XDEBUG_SESSION_START=16957,但我的所有断点都被忽略了。
为了获取更多信息,我运行了netstat

enter image description here

有人能告诉我这里缺少什么吗?

非常感谢您的帮助!


启用xdebug日志并分享一次不成功的调试会话的日志:https://xdebug.org/docs/all_settings#remote_log - LazyOne
2个回答

6
  1. 不要使用运行/调试配置进行Web调试,这样反而会产生负作用。您可以直接从浏览器使用零配置调试来启动调试连接。
  2. 禁用xdebug.remote_connect_back,它带来的负面影响比收益更多,特别是在使用Docker时。
  3. 当您使用Docker时,xdebug.remote_host不应为localhost,否则容器会尝试将调试数据发送到自身而不是主机。看起来您正在使用MacOS和Docker for Mac,在这种情况下,正确的主机名应为host.docker.internal
  4. 如果在您从浏览器启动PhpStorm调试会话后仍然无法捕获连接,则需要像@LazyOne建议的那样查看Xdebug日志。

展示PhpStorm中Docker基础知识的博客文章:https://blog.jetbrains.com/phpstorm/2018/08/quickstart-with-docker-in-phpstorm/


0

我使用了这个设置,它起作用了 :)

xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.default_enable=1
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.profiler_enable=0
xdebug.profiler_output_dir="/var/www/html"
xdebug.var_display_max_depth=20
xdebug.remote_host=host.docker.internal
xdebug.remote_enable=1
xdebug.remote_connect_back=0

在vscode中使用launch.json
 "name": "Listen 9000",
 "type": "php",
 "request": "launch",
 "log": true,
 "externalConsole": false,
 "pathMappings": {
        "/var/www/html": "/Users/folder/project/src"
     },
  "port": 9000,

使用 docker-compose.yml 文件:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接