【问题标题】:How to connect PhpStorm with Xdebug如何连接 PhpStorm 和 Xdebug
【发布时间】:2020-09-23 23:13:24
【问题描述】:

我希望这里有人可以帮助我解决我的问题:

我最近进入了我的第一个 PHP 项目,需要设置调试。我知道很多人在我之前遇到过同样的问题,但我很难找到解决方案。

我需要使用 Xdebug 设置 PhpStorm,并且所有设置仍然无法正常工作,当我开始调试会话时,我陷入了困境,没有更多信息:

这是我的项目设置:

带有 Xdebug 的 Docker Webapp:0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp

PhpStorm PHP 调试设置:

来自phpinfo()的Xdebug设置:

在 PhpStorm 中侦听调试连接已打开,开始调试会话通过 GET 创建会话:https://localhost/?XDEBUG_SESSION_START=16957 但我所有的断点都被忽略了。

为了获得更多信息我跑了netstat

谁能告诉我这里缺少什么?

非常感谢您!

【问题讨论】:

标签: php phpstorm xdebug


【解决方案1】:

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

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:

【讨论】:

    【解决方案2】:
    1. 不要使用运行/调试配置进行 Web 调试,这会适得其反。您可以使用zero-configuration debugging 直接从浏览器启动调试连接。
    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/

    【讨论】:

      猜你喜欢
      • 2015-09-25
      • 1970-01-01
      • 2020-02-19
      • 2016-10-01
      • 2018-06-03
      • 2014-11-23
      • 2019-08-05
      • 2021-02-25
      • 2015-08-03
      相关资源
      最近更新 更多