我尝试在我的Docker容器中设置Xdebug步骤调试器,以便能够连接到我的Docker容器。
这是我的项目中.vscode
目录下launch.json
的配置片段:
{
"name": "Xdebug",
"type": "php",
"request": "launch",
"hostname": "127.0.0.1",
"port": 9000,
"pathMappings": {
"/var/www/html/": "${workspaceFolder}/code/",
},
},
这是我的docker-compose.yml
的代码片段:
services:
webserver:
container_name: webserver_orderlinev3
build: webserver
ports:
- 8080:80
- 9000:9000
volumes:
- ./code:/var/www/html
- ./webserver/php-ini-overrides.ini:/usr/local/etc/php/conf.d/php-ini-overrides.ini
- ./webserver/phpsessions:/var/www/phpsessionfiles
- ./xdebuglog:/tmp/xdbglog
extra_hosts:
- host.docker.internal:host-gateway
environment:
- XDEBUG_MODE=debug,develop,coverage,profile,trace
还有那些我的php.ini覆盖了
[session]
session.save_handler=files
session.save_path="/var/www/phpsessionfiles"
[xdebug]
xdebug.client_port=9000
xdebug.mode=off
xdebug.discover_client_host=on
xdebug.client_host = host.docker.internal
xdebug.remote_connect_back=0
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.start_with_request = yes
xdebug.log=/tmp/xdbglog/xdebug_remote.log
因为这是xdebug.log的日志输出
[17] Log opened at 2022-10-25 16:22:46.248594
[17] [Step Debug] INFO: Checking remote connect back address.
[17] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[17] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[17] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.29.0.1:9000.
[17] [Step Debug] WARN: Creating socket for '172.29.0.1:9000', poll success, but error: Operation now in progress (29).
[17] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9000. :-|
[17] [Step Debug] INFO: Connected to debugging client: 172.29.0.1:9000 (from REMOTE_ADDR HTTP header), host.docker.internal:9000 (fallback through xdebug.client_host/xdebug.client_port). :-)
[17] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/orderline/api/index.php" language="PHP" xdebug:language_version="8.0.24" protocol_version="1.0" appid="17"><engine version="3.1.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2022 by Derick Rethans]]></copyright></init>
[17] [Step Debug] <- feature_set -i 1 -n max_children -v 100
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="max_children" success="1"></response>
[17] [Step Debug] <- feature_set -i 2 -n max_data -v 8192
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_data" success="1"></response>
[17] [Step Debug] <- breakpoint_set -i 3 -t exception -x "Notice"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="170008"></response>
[17] [Step Debug] <- breakpoint_set -i 4 -t exception -x "Warning"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="4" id="170009"></response>
[17] [Step Debug] <- breakpoint_set -i 5 -t exception -x "Error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="5" id="170010"></response>
[17] [Step Debug] <- breakpoint_set -i 6 -t exception -x "Exception"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="6" id="170011"></response>
[17] [Step Debug] <- breakpoint_set -i 7 -t exception -x "Fatal error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="7" id="170012"></response>
[17] [Step Debug] <- breakpoint_set -i 8 -t exception -x "Parse error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="8" id="170013"></response>
[17] [Step Debug] <- breakpoint_set -i 9 -t exception -x "Unknown error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="9" id="170014"></response>
[17] [Step Debug] <- run -i 10
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="10" status="stopping" reason="ok"></response>
[17] Log closed at 2022-10-25 16:22:46.308352
我没有得到任何线索,为什么它实际上是不工作的。
主机端口到访客端口的重定向似乎是工作,因为我可以通过localhost:8080
连接到Web服务器,我现在看了几个YouTube教程这个主题,但我不知道我做错了什么。
Xdebug似乎连接到docker.host.internal
,但网关似乎阻止了这一点-尽管我关闭了我的防火墙,甚至为了测试(再次打开它)。
有在Docker和Xdebug方面经验的人可以帮助我吗?我将非常感激。
另外,我没有使用任何VPN连接-它被禁用正是因为这个原因。
1条答案
按热度按时间sr4lhrrt1#
谢谢你,它现在终于开始运行了,如果没有@LazyOne,我可能会在这里多呆一段时间,特别感谢他〈3
这是配置
docker-compose.yml
第一个