如何连接 PhpStorm 和 Xdebug

How to connect PhpStorm with Xdebug

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

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

我需要使用 Xdebug 设置 PhpStorm,所有设置仍然无法正常工作,当我开始我的调试会话时,我卡在了这里,没有更多信息:

这是我的项目设置:

Docker 带有 Xdebug 的 Web 应用程序: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:

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

非常感谢您!

  1. 不要使用 run/debug 配置进行 Web 调试,这会适得其反。您可以使用 zero-configuration debugging.
  2. 直接从浏览器启动调试连接
  3. 禁用xdebug.remote_connect_back,弊大于利,尤其是Docker。
  4. 当您使用 Docker 时,
  5. xdebug.remote_host 不应该是 localhost,这样,容器会尝试将调试数据发送给自己而不是主机。看来您正在使用 macOS 和 Docker 作为 Mac,在这种情况下正确的主机名应该是 host.docker.internal
  6. 如果从浏览器启动调试会话后 PhpStorm 仍然无法捕获连接,我们需要按照@LazyOne 的建议查看 Xdebug 日志。

博客 post 显示 Docker PhpStorm 基础知识:https://blog.jetbrains.com/phpstorm/2018/08/quickstart-with-docker-in-phpstorm/

我使用了这个设置并且有效:)

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

与 launch.json 在 vscode

 "name": "Listen 9000",
 "type": "php",
 "request": "launch",
 "log": true,
 "externalConsole": false,
 "pathMappings": {
        "/var/www/html": "/Users/folder/project/src"
     },
  "port": 9000,

与docker-compose.yml: