简体   繁体   English

Xdebug: [Step Debug] 无法连接到调试客户端

[英]Xdebug: [Step Debug] Could not connect to debugging client

I would like to try Xdebug 3.0.0RC1 to explore what has changed and the new features that come with it.我想尝试 Xdebug 3.0.0RC1 来探索发生了什么变化以及随之而来的新功能。 I am also using the latest PhpStorm 2020.3 EAP which supports Xdebug 3 with no major config needed.我还使用最新的 PhpStorm 2020.3 EAP,它支持 Xdebug 3,无需主要配置。 Below is my PhpStorm config for the Debugger:下面是我的调试器的 PhpStorm 配置:

在此处输入图像描述

And here is the configuration I have tried for Xdebug3:这是我为 Xdebug3 尝试过的配置:

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal # here I tried several combinations like: "localhost", "127.0.0.1", "172.17.0.1"
xdebug.client_port=9001 # here I tried several ports 9003 included with no success

I have also tried not adding the client_host/client_port setting at all and still failing.我也试过根本不添加client_host/client_port设置,但仍然失败。

I am getting this error:我收到此错误:

Script php bin/console doctrine:cache:clear-metadata returned with error code 255
!!  [17-Nov-2020 15:24:40 UTC] Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9001 (through xdebug.client_host/xdebug.client_port) :-(
!!  [17-Nov-2020 15:24:41 UTC] PHP Fatal error:  Method class@anonymous::__toString() must not throw an exception, caught Symfony\Component\DependencyInjection\Exception\AutowiringFailedException:  in /var/www/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php on line 233

Some info about my environment:关于我的环境的一些信息:

  • Fedora 33软呢帽 33
  • Docker version 19.03.13, build 4484c46d9d Docker 版本 19.03.13,内部版本 4484c46d9d
  • PhpStorm 2020.3 EAP Build #PS-203.5784.36 PhpStorm 2020.3 EAP 构建 #PS-203.5784.36

It is curious (because apparently host.docker.internal is "not" supported by the Docker version I am using and yet it works) and weird at the same time that the following configuration does work with Xdebug 2 even having the debugger listening for incoming connections all the time:这很好奇(因为我正在使用的host.docker.internal版本显然“不”支持 host.docker.internal 但它仍然有效)并且很奇怪,同时以下配置确实适用于 Xdebug 2,甚至让调试器侦听传入一直连接:

在此处输入图像描述

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9000

What I am missing here?我在这里缺少什么?

Note: I already applied the solution provided by the Xdebug developer here .注意:我已经在这里应用了 Xdebug 开发者提供的解决方案。

PHP 7.4 PHP 7.4
Docker码头工人
PHPStorm 2020.1 PHPStorm 2020.1
Xdebug 3.1.0 Xdebug 3.1.0

Install Xdebug in your docker container using Dockerfile使用 Dockerfile 在您的 docker 容器中安装 Xdebug

RUN pecl install xdebug-3.0.1 && docker-php-ext-enable xdebug

Configure php.ini with following:使用以下配置 php.ini:

[xdebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = 1

Go to PHPStorm - Settings - PHP - Debug - Xdebug and set the port to 9003 (by default)转到 PHPStorm - Settings - PHP - Debug - Xdebug 并将端口设置为9003 (默认)

PHPStorm PHPStorm

That's it (:就是这样 (:

If you want to enable/disable debugger only when you need it: just install a browser extension called "Xdebug helper", select "Debug" and remove "xdebug.start_with_request = yes" from php.ini如果您只想在需要时启用/禁用调试器:只需安装一个名为“Xdebug helper”的浏览器扩展,选择“Debug”并从 php.ini 中删除“xdebug.start_with_request = yes”

[xdebug]
xdebug.mode = debug
xdebug.discover_client_host = 1

I will start saying big thanks to @LazyOne who spent some time helping me on this one until we make it to work.我将开始对@LazyOne 表示非常感谢,他花了一些时间帮助我解决这个问题,直到我们成功。 Here is how the config looks like for me currently and it is working fine:以下是我目前的配置,并且它工作正常:

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.mode=debug
xdebug.client_port=9005

You need also to update the Xdebug port at File | Settings | Languages & Frameworks | PHP | Servers您还需要在File | Settings | Languages & Frameworks | PHP | Servers更新 Xdebug 端口。 File | Settings | Languages & Frameworks | PHP | Servers File | Settings | Languages & Frameworks | PHP | Servers to reflect the new one but also enable the option to listen on Xdebug3 incoming connections. File | Settings | Languages & Frameworks | PHP | Servers反映了新的File | Settings | Languages & Frameworks | PHP | Servers ,但也启用了侦听 Xdebug3 传入连接的选项。 (I believe it is enabled by default in PhpStorm 2020.3) (我相信它在 PhpStorm 2020.3 中默认启用)

在此处输入图片说明

That is the setup for a backend project where no browser is in the middle, I have not tried but for those, you might need:这是中间没有浏览器的后端项目的设置,我没有尝试过,但对于那些,您可能需要:

xdebug.start_with_request=yes

And also have File | Settings | Languages & Frameworks | PHP | Servers还有File | Settings | Languages & Frameworks | PHP | Servers File | Settings | Languages & Frameworks | PHP | Servers File | Settings | Languages & Frameworks | PHP | Servers well configured. File | Settings | Languages & Frameworks | PHP | Servers配置良好。

Note: We found the host had enabled IPv6 and I disabled it and in addition, added the following setting to the IDE through Help > Edit Custom VM options : -Djava.net.preferIPv4Stack=true .注意:我们发现主机已启用 IPv6,我将其禁用,此外,通过“ Help > Edit Custom VM options将以下设置添加到 IDE 中: -Djava.net.preferIPv4Stack=true After added the IP4 setting to the IDE I haven't tried re-enabling IPv6 and see if Xdebug 3 still working将 IP4 设置添加到 IDE 后,我还没有尝试重新启用 IPv6 并查看 Xdebug 3 是否仍在工作

I created a very simple configuration that allows me to use Xdebug with any PHP version with minimal effort (v2: 5.6-7.1, v3: 7.2+) .我创建了一个非常简单的配置,允许我以最小的努力将Xdebug与任何 PHP 版本一起使用(v2: 5.6-7.1, v3: 7.2+) All I need to do is configure PhpStorm and docker-compose.yml in three places and I can debug.我需要做的就是在三个地方配置PhpStormdocker-compose.yml ,我就可以调试了。

Configuration:配置:

gander/dev @ xdebug2.ini : gander/dev @ xdebug2.ini

zend_extension=xdebug.so
; https://2.xdebug.org/docs/all_settings
; ------------------------------------
; Enables Step Debugging
xdebug.remote_enable=1
; ------------------------------------
; Address where IDE listening for incoming debugging connections
xdebug.remote_host=host.docker.internal
; ------------------------------------
; Port where IDE listening for incoming debugging connections
xdebug.remote_port=9003
; ------------------------------------
; Color var_dumps when in CLI
xdebug.cli_color=1
; ------------------------------------

gander/dev @ xdebug3.ini : gander/dev @ xdebug3.ini

zend_extension=xdebug.so
; https://xdebug.org/docs/all_settings
; ------------------------------------
; Enables Step Debugging
xdebug.mode=debug,develop
; ------------------------------------
; Address where IDE listening for incoming debugging connections
xdebug.client_host=host.docker.internal
; ------------------------------------
; Port where IDE listening for incoming debugging connections
xdebug.client_port=9003
; ------------------------------------
; Color var_dumps when in CLI
xdebug.cli_color=1
; ------------------------------------

gander/dev @ docker-compose.yml : gander/dev @ docker-compose.yml

version: '3.7'

services:
#...
  dev74:
    hostname: 'dev-74'
    container_name: 'dev_74'
    image: 'gander/dev:7.4'
    volumes:
      - './app/xdebug3:/www/localhost'
    working_dir: '/www/localhost/public'
    ports:
      - '8074:80'
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      PHP_IDE_CONFIG: "serverName=dev.74"
#...

Run via CLI:通过 CLI 运行:

XDEBUG_SESSION=1 XDEBUG_CONFIG=1 php script.php

or:或者:

docker-compose exec dev74 bash -c 'XDEBUG_SESSION=1 XDEBUG_CONFIG=1 php index.php'

Screenshots:截图:

调试端口 配置 验证

I had the same issue.我遇到过同样的问题。 I still have it when doing a request from a browser, but from the commandline, like in your case, it now works.从浏览器发出请求时,我仍然拥有它,但是从命令行,就像你的情况一样,它现在可以工作了。 What I was missing was a Server configuration with a path mapping.我缺少的是带有路径映射的服务器配置。 Once it set that up, along with the settings that you already have, it worked.一旦它设置好,连同你已经拥有的设置,它就起作用了。 I am on Mac Os Big Sur, using PhpStorm 2020.3我在 Mac Os Big Sur 上,使用 PhpStorm 2020.3

PHP 7.3 PHP 7.3
Docker (for Mac) Docker(适用于 Mac)
PhpStorm 2021.1 PhpStorm 2021.1


You may not need to install it via PECL (which took a long time to build and didn't work for me).您可能不需要通过 PECL 安装它(这需要很长时间来构建并且对我不起作用)。

All I did was adding php7.3-xdebug to my apt-get install command and configure the port mapping correctly as follows:我所做的只是将php7.3-xdebug添加到我的apt-get install命令并正确配置端口映射,如下所示:

In Dockerfile add: RUN apt-get install -y php7.3-xdebug在 Dockerfile 添加: RUN apt-get install -y php7.3-xdebug

In docker-compose.yml I mapped an extra_host (this was the secret sauce for me):在 docker-compose.yml 中,我映射了一个extra_host (这是我的秘诀):

services:
  web:
    extra_hosts:
      - "host.docker.internal:host-gateway"

In php.ini:在 php.ini 中:

[xdebug]
xdebug.mode=debug
xdebug.client_host=host.docker.internal

;optionals: (uncomment if you need them)
;xdebug.start_with_request=yes
;xdebug.discover_client_host=1

In PhpStorm I just started listening to port 9003 and configured the server mapping to my needs.在 PhpStorm 中,我刚刚开始侦听端口 9003 并根据我的需要配置服务器映射。

References:参考:

What worked for me was to change start_with_request from yes to trigger .对我start_with_requeststart_with_requestyes更改为trigger

This worked for me:这对我有用:

xdebug.mode=debug
xdebug.start_with_request=trigger
xdebug.client_port=9003

I would like to point the attention to the following configuration option in the ini file, because that is what solved the same problem for me.我想指出 ini 文件中的以下配置选项,因为它为我解决了同样的问题。

xdebug.client_host=host.docker.internal

In PhpStorm's documentation here says that xdebug.remote_host=host.docker.internal has to be configured which seams similar, but is not.在 PhpStorm 的文档中, 这里xdebug.remote_host=host.docker.internal必须配置其接缝相似,但不是。

A slight difference is that I use IntelliJ.一个细微的区别是我使用 IntelliJ。

I had same problem ( ubuntu 20.4 - docker 20.10 - xdebug 3)我有同样的问题(ubuntu 20.4 - docker 20.10 - xdebug 3)

My solution was:我的解决方案是:

  1. xdebug.discover_client_host=1
  2. Disable firewall sudo ufw disable禁用防火墙sudo ufw disable

If you have tried all the above answers and still cannot connect to XDebug server, try to turn off your local firewall or add the ALLOW rule for your Xdebug port ( 9003 by default).如果您已经尝试了上述所有答案,但仍然无法连接到 XDebug 服务器,请尝试关闭本地防火墙或为您的 Xdebug 端口添加ALLOW规则(默认为9003 )。

Ubuntu firewall interface is ufw and you can allow port 9003 by issuing the following command: Ubuntu 防火墙接口是ufw ,您可以通过发出以下命令来允许端口 9003:

sudo ufw allow 9003

Verify the changes with:验证更改:

sudo ufw status

To remove this error displaying in the console.删除控制台中显示的此错误。 Please mention the log path Xdebug going to use to store the logs.请提及 Xdebug 用于存储日志的日志路径。 something similar mention below下面有类似的提及

xdebug.log=/var/www/var/log/xdebug.log

I have the same issue if i'm working with the CLI:如果我使用 CLI,我会遇到同样的问题:

Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(

And this is my configuration that causes the warning message:这是导致警告消息的我的配置:

[XDebug]
...
xdebug.mode=develop,debug
xdebug.discover_client_host=1
xdebug.start_with_request = yes
xdebug.client_host = 127.0.0.1
xdebug.client_port = 9003

I'm using the config for debugging from the URL, which is using the FPM, and it's working fine.我正在使用来自 URL 的调试配置,它使用 FPM,并且工作正常。

However, if I'm working with the CLI, then I must change the config, especially the xdebug.start_with_request但是,如果我使用 CLI,那么我必须更改配置,尤其是xdebug.start_with_request

before (FPM):之前(FPM):

xdebug.start_with_request = yes xdebug.start_with_request = 是

after (CLI):之后(CLI):

xdebug.start_with_request = trigger xdebug.start_with_request = 触发器

As an additional information, I'm using Xdebug 3.作为附加信息,我正在使用 Xdebug 3。

暂无
暂无

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

相关问题 Xdebug:[Step Debug] 无法连接到调试客户端。 试过:localhost:9003(通过 xdebug.client_host/xdebug.client_port 回退):-( - Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (fallback through xdebug.client_host/xdebug.client_port) :-( XDebug 无法连接到客户端 - XDebug could not connect to client Xdebug 无法连接到调试客户端。 试过:本地主机:9000 - Xdebug Could not connect to debugging client. Tried: localhost:9000 Xdebug: 无法连接到调试客户端 (Phpstorm + WSL2) - Xdebug: Could not connect to debugging client (Phpstorm + WSL2) Xdebug: [Step Debug] 连接调试客户端超时,等待:200 ms。 试过:本地主机:9003 - Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 Docker + Xdebug + VSCode 无法连接到客户端 - Docker + Xdebug + VSCode Could not connect to client Xdebug 无法连接到客户端,从哪里开始调试调试器? - Xdebug unable to connect to client, where do I start debugging the debugger? PHP远程调试:XDebug无法连接到JetBrains的php Storm客户端 - PHP remote debugging: XDebug can't connect to JetBrains php Storm client Xdebug 3 无法从 Docker [20.10.12] 连接到 PhpStorm 调试客户端。 Ubuntu - Xdebug 3 couldn't connect from Docker [20.10.12] to PhpStorm debug client. Ubuntu 循序渐进:如何对客户端 IDE 的连接进行 Xdebug 故障排除 - Step-by-step: How to do Xdebug troubleshooting connection to client IDE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM