我正在尝试使用 Lando (v. 3.0.24) 和 VSCode 设置 Xdebug,但没有成功。我已经阅读了官方指南以及互联网上的其他内容,以及与我的问题相似的不同主题,但可惜我无法让它工作。
我在文件夹中的lando文件docroot
是:
name: mysite
recipe: drupal9
services:
appserver:
webroot: .
xdebug: debug
config:
php: ../.vscode/php.ini
php.ini 文件是:
[PHP]
; Xdebug
xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.log = /tmp/xdebug.log
; Remote settings
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = ${LANDO_HOST_IP}
; xdebug.remote_connect_back = 1
xdebug.remote_log = /tmp/xdebug_remote.log
最后,launch.json 文件是:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug (9003)",
"type": "php",
"request": "launch",
"port": 9003,
"log": true,
"pathMappings": {
"/app/": "${workspaceRoot}/",
}
}
]
}
顺便说一句,我不确定如何设置pathMappings
,所以我尝试了不同的组合,例如
- "/app/": "${workspaceRoot}/",
- "/app/": "${workspaceRoot}/docroot",
- "/app/": "${workspaceFolder}/",
- "/app/": "${workspaceFolder}/docroot",
无论如何,问题在于 Xdebug 不会在断点处停止。
如果我跟踪 xdebug.log,我会看到:
www-data@6137da628b8c:/app$ tail -f /tmp/xdebug.log [186] [Step Debug] INFO: Checking remote connect back address.
[186] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[186] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[186] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.20.0.1:9003.
[186] [Step Debug] WARN: Creating socket for '172.20.0.1:9003', poll success, but error: Operation now in progress (29).
[186] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: 172.24.0.1:9003. :-|
[186] [Step Debug] WARN: Creating socket for '172.24.0.1:9003', poll success, but error: Operation now in progress (29).
[186] [Step Debug] ERR: Could not connect to debugging client. Tried: 172.20.0.1:9003 (from REMOTE_ADDR HTTP header), 172.24.0.1:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
[186] Log closed at 2021-01-05 17:11:27.454926
[192] Log opened at 2021-01-05 17:12:03.777860
[192] [Step Debug] INFO: Checking remote connect back address.
[192] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[192] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.20.0.1:9003.
[192] [Step Debug] INFO: Connected to debugging client: 172.20.0.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header). :-)
[192] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///app/index.php" language="PHP" xdebug:language_version="7.4.13" protocol_version="1.0" appid="192"><engine version="3.0.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2020 by Derick Rethans]]></copyright></init>
[192] [Step Debug] <- breakpoint_list -i 1
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>
[192] [Step Debug] <- breakpoint_list -i 2
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="2"></response>
[192] [Step Debug] <- breakpoint_set -i 3 -t line -f file:///app/docroot/sites/default/settings.local.php -n 873
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="1920001"></response>
[192] [Step Debug] <- breakpoint_set -i 4 -t line -f file:///app/docroot/test.php -n 3
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="4" id="1920002"></response>
[192] [Step Debug] <- breakpoint_list -i 5
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="5"><breakpoint type="line" filename="file:///app/docroot/test.php" lineno="3" state="enabled" hit_count="0" hit_value="0" id="1920002"></breakpoint><breakpoint type="line" filename="file:///app/docroot/sites/default/settings.local.php" lineno="873" state="enabled" hit_count="0" hit_value="0" id="1920001"></breakpoint></response>
[192] [Step Debug] <- breakpoint_list -i 6
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="6"><breakpoint type="line" filename="file:///app/docroot/test.php" lineno="3" state="enabled" hit_count="0" hit_value="0" id="1920002"></breakpoint><breakpoint type="line" filename="file:///app/docroot/sites/default/settings.local.php" lineno="873" state="enabled" hit_count="0" hit_value="0" id="1920001"></breakpoint></response>
[192] [Step Debug] <- run -i 7
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="7" status="stopping" reason="ok"></response>
[192] [Step Debug] <- stop -i 8
[192] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="8" status="stopped" reason="ok"></response>
[192] Log closed at 2021-01-05 17:12:21.963742
那么也许 Xdebug 仍然无法连接到正确的 IP?无论如何,知道如何解决\可以让它工作吗?谢谢
编辑:如果我将lando.yml 文件从doocroot 文件夹移动到上面的文件夹,我可以得到一些工作情况,Xdebug 实际上停止在VSCode 中。但是还有另外两个问题:
- 不能再使用
lando drush
了。解决此问题的方法是,lando composer require drush/drush
但不知道为什么“全球”的lando 热潮不起作用。 - 终端命令 - 例如 drush - 似乎不适用于 xdebug(至少对我来说是一个非常小的问题),因为它们返回
Xdebug:[Step Debug] 无法连接到调试客户端。尝试过:172.31.206.147:9003(通过 xdebug.client_host/xdebug.client_port 回退):-(
在更新的 php.ini 和lando.yml 文件下面,launch.json 与上面相同。
[PHP]
; Xdebug
xdebug.max_nesting_level = 512
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.log = /tmp/xdebug.log
xdebug.remote_log = /tmp/xdebug_remote.log
name: myproject
recipe: drupal9
services:
appserver:
webroot: docroot
xdebug: debug
config:
php: .vscode/php.ini