1

我正在尝试使用 VSCode、php-debug 扩展、本地计算机上的远程 SSH 和远程计算机上的 XDebug + PHP 7.3 设置远程调试。使用远程 SSH 我可以成功连接到远程机器,浏览和编辑代码。我的 launch.json 有两种调试模式:1)在当前脚本上启动;2) 听 Xdebug。当我尝试使用第一种方法调试远程机器上的代码时,它工作得很好。我可以在当前机器上看到 php-debug 日志,在远程机器上也可以看到 xdebug 日志。但是当我在 VS Code 上的 Listen for XDebug 模式下启动调试器时,它看起来像是开始监听了。但是当我在浏览器上加载站点时,它不会在断点处停止。xdebug 日志中也没有记录任何内容。

这就是我的 launch.json 的样子

{
// 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": 9002,
        "log": true
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9002,
        "log": true
    }
]

}

这是我在远程服务器上的 xdebug 配置

[XDebug]
zend_extension = "/opt/remi/php73/root/usr/lib64/php/modules/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_log="/tmp/xdebug.log"
xdebug.profiler_enable=0
xdebug.remote_connect_back=1
xdebug.remote_port=9002
xdebug.remote_autostart=1
xdebug.remote_handler=dbgp

请注意,我没有代码的本地副本,我也不想拥有。这就是这个设置的重点。

我很感激任何帮助。谢谢

4

1 回答 1

0

对我来说,一个问题是 xdebug 正在侦听 TCPv6 端口但连接到 TCPv4 端口。指定 "hostname":"localhost" 使其监听 TCPv4 端口

{
   "name": "Listen for Xdebug",
   "type": "php",
   "request": "launch",
   "stopOnEntry": false,
   "hostname": "localhost",
   "port": 9003,
   // server -> local
   "pathMappings": {
     "/var/www/": "${workspaceRoot}/",
   }
},
于 2021-09-21T14:55:10.553 回答