x通过 vs 代码远程调试?

问题描述 投票:0回答:0

我的设置是运行 Docker 的远程服务器。我通过 VS Code 的远程 ssh 连接到远程。

我使网络请求抛出一个反向代理。这里所说的是我在 php.ini 中的 xdebug 配置选项:

xdebug.mode = debug
xdebug.client_host = "host.docker.internal" ; Linux
xdebug.remote_handler = dbgp
xdebug.start_with_request = yes
xdebug.client_port = ${XDEBUG_REMOTE_PORT}

现在我有

XDEBUG_REMOTE_PORT = 9998
。我还从 docker 容器内部确认
host.docker.internal
解析为
72.24.0.1
.

我尝试从主机运行

nc -vz localhost 9998
,它工作正常,所以我知道 vs code 正在监听。如果我从 docker 容器内部尝试
nc -vz host.docker.internal 9998
,它将无法连接。

这是有点奇怪的地方。如果我从 docker 容器内部在我的本地机器上尝试相同的

nc
命令,它工作得很好。

如果我在远程主机上运行

sudo lsof -i -P -n | grep LISTEN
,我得到:

所以在这一点上我不知道为什么

nc
在本地工作但在通过 ssh 连接时不会工作。

这也是我的 launch.json,我在其中添加了主机名,因此它将绑定到 v4 ip 地址而不是 v6:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9998,
            "hostname": "localhost",
            "pathMappings": {
                "/var/www/html": "${workspaceFolder}/www"
            },
            "xdebugSettings": {
                "max_data": -1,
                "max_depth": 1,
                "max_children": 100

            }
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003
        }
    ]
}

我的 docker-compose.json 中也有这一行:

    extra_hosts:
      - "host.docker.internal:host-gateway" # Linux host

有人对此有什么想法吗?

php docker xdebug
© www.soinside.com 2019 - 2024. All rights reserved.