![](/img/trans.png)
[英]Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
[英]Xdebug: [Step Debug] Could not connect to debugging client
我想嘗試 Xdebug 3.0.0RC1 來探索發生了什么變化以及隨之而來的新功能。 我還使用最新的 PhpStorm 2020.3 EAP,它支持 Xdebug 3,無需主要配置。 下面是我的調試器的 PhpStorm 配置:
這是我為 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
我也試過根本不添加client_host/client_port
設置,但仍然失敗。
我收到此錯誤:
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
關於我的環境的一些信息:
這很好奇(因為我正在使用的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
我在這里缺少什么?
注意:我已經在這里應用了 Xdebug 開發者提供的解決方案。
PHP 7.4
碼頭工人
PHPStorm 2020.1
Xdebug 3.1.0
使用 Dockerfile 在您的 docker 容器中安裝 Xdebug
RUN pecl install xdebug-3.0.1 && docker-php-ext-enable xdebug
使用以下配置 php.ini:
[xdebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = 1
轉到 PHPStorm - Settings - PHP - Debug - Xdebug 並將端口設置為9003 (默認)
就是這樣 (:
如果您只想在需要時啟用/禁用調試器:只需安裝一個名為“Xdebug helper”的瀏覽器擴展,選擇“Debug”並從 php.ini 中刪除“xdebug.start_with_request = yes”
[xdebug]
xdebug.mode = debug
xdebug.discover_client_host = 1
我將開始對@LazyOne 表示非常感謝,他花了一些時間幫助我解決這個問題,直到我們成功。 以下是我目前的配置,並且它工作正常:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.mode=debug
xdebug.client_port=9005
您還需要在File | Settings | Languages & Frameworks | PHP | Servers
更新 Xdebug 端口。 File | Settings | Languages & Frameworks | PHP | Servers
File | Settings | Languages & Frameworks | PHP | Servers
反映了新的File | Settings | Languages & Frameworks | PHP | Servers
,但也啟用了偵聽 Xdebug3 傳入連接的選項。 (我相信它在 PhpStorm 2020.3 中默認啟用)
這是中間沒有瀏覽器的后端項目的設置,我沒有嘗試過,但對於那些,您可能需要:
xdebug.start_with_request=yes
還有File | Settings | Languages & Frameworks | PHP | Servers
File | Settings | Languages & Frameworks | PHP | Servers
File | Settings | Languages & Frameworks | PHP | Servers
配置良好。
注意:我們發現主機已啟用 IPv6,我將其禁用,此外,通過“
Help > Edit Custom VM options
將以下設置添加到 IDE 中:-Djava.net.preferIPv4Stack=true
。 將 IP4 設置添加到 IDE 后,我還沒有嘗試重新啟用 IPv6 並查看 Xdebug 3 是否仍在工作
我創建了一個非常簡單的配置,允許我以最小的努力將Xdebug
與任何 PHP 版本一起使用(v2: 5.6-7.1, v3: 7.2+) 。 我需要做的就是在三個地方配置PhpStorm和docker-compose.yml
,我就可以調試了。
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
; ------------------------------------
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
:
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"
#...
XDEBUG_SESSION=1 XDEBUG_CONFIG=1 php script.php
或者:
docker-compose exec dev74 bash -c 'XDEBUG_SESSION=1 XDEBUG_CONFIG=1 php index.php'
我遇到過同樣的問題。 從瀏覽器發出請求時,我仍然擁有它,但是從命令行,就像你的情況一樣,它現在可以工作了。 我缺少的是帶有路徑映射的服務器配置。 一旦它設置好,連同你已經擁有的設置,它就起作用了。 我在 Mac Os Big Sur 上,使用 PhpStorm 2020.3
PHP 7.3
Docker(適用於 Mac)
PhpStorm 2021.1
您可能不需要通過 PECL 安裝它(這需要很長時間來構建並且對我不起作用)。
我所做的只是將php7.3-xdebug
添加到我的apt-get install
命令並正確配置端口映射,如下所示:
在 Dockerfile 添加: RUN apt-get install -y php7.3-xdebug
在 docker-compose.yml 中,我映射了一個extra_host
(這是我的秘訣):
services:
web:
extra_hosts:
- "host.docker.internal:host-gateway"
在 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
在 PhpStorm 中,我剛剛開始偵聽端口 9003 並根據我的需要配置服務器映射。
參考:
對我start_with_request
的是將start_with_request
從yes更改為trigger
。
這對我有用:
xdebug.mode=debug
xdebug.start_with_request=trigger
xdebug.client_port=9003
我想指出 ini 文件中的以下配置選項,因為它為我解決了同樣的問題。
xdebug.client_host=host.docker.internal
在 PhpStorm 的文檔中, 這里說xdebug.remote_host=host.docker.internal
必須配置其接縫相似,但不是。
一個細微的區別是我使用 IntelliJ。
我有同樣的問題(ubuntu 20.4 - docker 20.10 - xdebug 3)
我的解決方案是:
xdebug.discover_client_host=1
sudo ufw disable
如果您已經嘗試了上述所有答案,但仍然無法連接到 XDebug 服務器,請嘗試關閉本地防火牆或為您的 Xdebug 端口添加ALLOW
規則(默認為9003
)。
Ubuntu 防火牆接口是ufw
,您可以通過發出以下命令來允許端口 9003:
sudo ufw allow 9003
驗證更改:
sudo ufw status
刪除控制台中顯示的此錯誤。 請提及 Xdebug 用於存儲日志的日志路徑。 下面有類似的提及
xdebug.log=/var/www/var/log/xdebug.log
如果我使用 CLI,我會遇到同樣的問題:
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
這是導致警告消息的我的配置:
[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
我正在使用來自 URL 的調試配置,它使用 FPM,並且工作正常。
但是,如果我使用 CLI,那么我必須更改配置,尤其是xdebug.start_with_request
之前(FPM):
xdebug.start_with_request = 是
之后(CLI):
xdebug.start_with_request = 觸發器
作為附加信息,我正在使用 Xdebug 3。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.