繁体   English   中英

xdebug 连接拒绝 Docker 容器

[英]xdebug connection refused to Docker container

错误:

2020/04/26 23:43:48 [error] 8#8: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.208.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://192.168.208.3:9000", host: "127.0.0.1", referrer: "http://127.0.0.1/"

无法与 xdebug 建立连接。 Docker 配置取自这里https://gitlab.com/martinpham/symfony-5-docker/-/tree/master/docker

xdebug 是单独安装的,它被 IDE 识别。

在 php-fpm 环境下的 docker-compose.yml 中也添加了这个:

environment:
- XDEBUG_CONFIG:remote_host=host.docker.internal remote_enable=1 remote_autostart=off xdebug.idekey=PHPSTORM

还需要添加/修改什么?

这就是我最近为 http 服务设置 docker + php + xdebug 的方式。 我指导我的同龄人完成了它,它完美无缺。

1. 将 ENV PHP_IDE_CONFIG 添加到您的 docker fpm 池配置中

您需要将此环境添加到您的 php-fpm 池配置中。 它可能是www.conf (例如)

env[PHP_IDE_CONFIG] = "serverName=localhost"

2. 将 xdebug.ini 添加到您的 docker 容器中

这是我用于设置的 xdebug.ini 示例:

xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = off
xdebug.remote_host = host.docker.internal
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
xdebug.max_nesting_level = 1500

3. [IntelliJ IDEA 或 PHPStorm] - 设置 PHP 服务器

  1. 打开Preferences
  2. Go 到Languages & Frameworks -> PHP -> Servers
  3. 名称设置为localhost (这很重要,应该与PHP_IDE_CONFIG值匹配)
  4. 主机设置为本地主机
  5. 启用use path mappings
  6. Map 您的项目根路径到 docker 工作目录(例如/var/www/html ),因此 IntelliJ 可以正确 map 路径。

4. [IntelliJ IDEA 或 PHPStorm] - 设置 IDE 键

  1. 打开Preferences
  2. Go 到Languages & Frameworks -> PHP -> Debug -> DGBp proxy
  3. IDE 密钥设置为PHPSTORM

5. 将 XDEBUG_SESSION=PHPSTORM 添加到您的 url/cookie..

最后:

  • 添加?XDEBUG_SESSION=PHPSTORM到您的 url 或
  • 添加一个名为XDBEUG_SESSION和值PHPSTORM的 cookie

问题出现在:环境:

- XDEBUG_CONFIG:remote_host=host.docker.internal remote_enable=1 remote_autostart=off xdebug.idekey=PHPSTORM
  1. 它没有正确解析。
  2. 如果我只传递 remote_host=host.docker.internal 那么它将传递“localhost”而不是主机 IP 地址。

我知道这篇文章是针对 PHPStorm 用户的,但是如果任何 VSCode 用户在这里偶然发现,那么需要做两件与 PHPStorm 不同的事情(更多内容请参见 PHPStorm https://stackoverflow.com/a/61561910/3056278的答案)-

  1. 传递您主机的 IP 地址(192.168 ...)而不是host.docker.internal
  2. 在调试启动配置中配置 pathMappings -
{
    "name": "Debug Docker",
    "type": "php",
    "request": "launch",
    "port": 9000,
    "pathMappings": {
        "/var/www/app": "${workspaceFolder}"
    }
},

/var/www/app替换为您自己的路径!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM