Php xdebug连接拒绝Docker容器

Php xdebug连接拒绝Docker容器,php,docker,nginx,docker-compose,xdebug,Php,Docker,Nginx,Docker Compose,Xdebug,错误: 无法与xdebug建立连接。 Docker配置是从这里获取的 xdebug是单独安装的,它由IDE识别 在php fpm环境下的docker-compose.yml中还添加了以下内容: 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, re

错误:

无法与xdebug建立连接。 Docker配置是从这里获取的

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

在php fpm环境下的docker-compose.yml中还添加了以下内容:

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.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

还有什么需要添加/修改的?

这就是我最近为http服务设置docker+php+xdebug的方式。我指导我的同龄人完成了这项工作,结果完美无瑕

1.将ENV PHP_IDE_CONFIG添加到docker fpm池配置中 您需要将此环境添加到php fpm池配置中。它可以是
www.conf
(例如)

2.将xdebug.ini添加到docker容器 下面是我用于设置的xdebug.ini的一个示例:

env[PHP_IDE_CONFIG] = "serverName=localhost"
3.[IntelliJ IDEA或PHPStorm]-设置PHP服务器
  • 打开
    首选项
  • 转到
    语言和框架
    ->
    PHP
    ->
    服务器
  • Name设置为localhost(这很重要,应该匹配
    PHP\u IDE\u CONFIG
    值)
  • 将主机设置为本地主机
  • 启用
    使用路径映射
  • 将项目根路径映射到docker workdir(例如,
    /var/www/html
    ),以便IntelliJ能够正确映射路径
  • 4.[IntelliJ IDEA或PHPStorm]-设置IDE密钥
  • 打开
    首选项
  • 转到
    Languages&Frameworks
    ->
    PHP
    ->
    Debug
    ->
    DGBp proxy
  • 将IDE键设置为PHPSTORM
  • 5.将XDEBUG_SESSION=PHPSTORM添加到url/cookie。。 最后:

    • ?XDEBUG\u SESSION=PHPSTORM
      添加到您的url或
    • 添加一个名为
      XDBEUG\u SESSION
      且值为
      PHPSTORM
    问题在于: 环境:

    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.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
    
  • 它没有被正确解析
  • 如果我只传递remote_host=host.docker.internal,那么它将传递“localhost”,而不是主机IP地址

  • 我知道这篇文章是为PHPStorm用户写的,但是如果有任何VSCode用户在这里偶然发现,那么PHPStorm需要做两件不同的事情(更多关于PHPStorm的回答)-

  • 传递主机的IP地址(192.168…),而不是
    host.docker.internal
  • 在调试启动配置中配置路径映射-
  • {
    “名称”:“调试Docker”,
    “类型”:“php”,
    “请求”:“启动”,
    “港口”:9000,
    “路径映射”:{
    “/var/www/app”:“${workspaceFolder}”
    }
    },
    

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

    你在docker日志中还看到了什么?你能粘贴你的xdebug.ini配置和PHPStorm的xdebug调试端口以及DBGp代理设置吗?你能在这里提供你的xdebug设置吗?这里的第2部分是最重要的,因为调试器需要知道调试开始时连接到什么。具有描述主机、容器和IDE如何互连的架构。这篇文章的作者给出的答案是详尽的。