我正试图用带有VSCode的Lando(3.0.24版(设置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文件从dooclot文件夹移到上面的文件夹,我可以得到一个有点工作的情况,Xdebug实际上在VSCode中停止。然而,还有另外两个问题:
- 无法再使用
lando drush
。对此的变通方法是CCD_ 4;全局";兰多的德鲁什不起作用 - 终端命令(例如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
我不确定这是否是你的情况,但我会告诉你我是如何解决这个问题的:
我通过将此行添加到php.ini(在/etc/php/7.4/cli/php.ini
中(来解决将error_log指向有效位置的问题:
error_log = /var/www/log/php_error.log
请将该位置更改为所需的任何有效目录,然后重试。警告应该从输出中消失,现在转到日志文件。