【问题标题】:VS Code launch.json Xdebug configuration for step debugging PHP pages in a Windows Server 8VS Code launch.json Xdebug 配置,用于在 Windows Server 8 中逐步调试 PHP 页面
【发布时间】:2021-12-25 17:55:36
【问题描述】:

我在 Windows Server 8 上有一个 PHP 项目,我希望能够从 VS Code 处理这些页面并进行分步调试,但我不知道如何正确配置 launch.json。

我在 Windows Server 上安装了 Xdebug 3 并且它处于活动状态。我在php.ini里放的配置是这样的:

[XDebug]
zend_extension = xdebug
xdebug.mode= debug, develop
xdebug.start_with_request=yes
xdebug.idekey=VSCODE
xdebug.remote_port = 9003
xdebug.discover_client_host = true
xdebug.client_discovery_header = HTTP_XDEBUG_IP
xdebug.show_exception_trace = 1
xdebug.connect_timeout_ms = 5000

考虑到:

  • “11.128.7.124:3555”是该服务器上 Apache 使用的 IP Windows 服务器和端口。

  • 我从 VS Code 打开服务器 PHP 文件夹抛出一个网络单元。

  • 在 Windows 8 服务器上安装了 XAMPP 和 PHP 7.2

我已经阅读了很多信息,但是我已经能够配置环境来执行我在本地打开该项目时可以执行的步骤调试。

我还在 Microsoft Edge 和 Google Chrome 浏览器(活动)中安装了 Xdebug 扩展。

VS Code 上的launch.json 文件有这样的配置(IP 地址和端口不一样):

{
    // 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": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "11.128.7.124:3555"
            ],
            "program": "",
            "cwd": "${fileDirname}",
            "port": 9003,
            "pathMappings": {
                "d:/xampp/htdocs/myproject": "${workspaceFolder}/htdocs",
                "/myproject": "${workspaceFolder}"
              },
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        },
        
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },

        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        }

    ]
}

这是xdebug_info()函数输出:



【问题讨论】:

    标签: php xdebug remote-debugging vscode-debugger vscode-remote


    【解决方案1】:

    我认为你的问题是:

    xdebug.remote_port = 9003
    

    该设置已在 Xdebug 3 中重命名为 xdebug.client_port (https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_port)。

    或者,您可以修改launch.json,使其还将端口设置为“启动内置网络服务器”案例中相同启动配置的port设置。

            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-dxdebug.client_port=${port}",
                "-S",
                "11.128.7.124:3555"
            ],
    

    提示

    为了调试 Xdebug 调试的问题,您可以在您尝试调试的脚本中使用新的 Xdebug 3 函数xdebug_info(),它会向您显示正在发生的事情、Xdebug 尝试过的内容的诊断信息,以及它是否可以连接到调试器等。

    【讨论】:

    • 你是对的@Derick,它在xdebug upgrade guide 中指出,但我错过了。我已经改过了,但即使 xdebug 识别出我的 IP 地址,它也不起作用。
    • xdebug_info() 输出表明 Xdebug 连接到客户端......所以它似乎工作正常。您可能没有设置断点吗?也许打开“第一行中断”?
    • 是的@Derick,我已经设置了断点,就像我之前在进行 PHP 单步调试时所做的那样,这次的不同之处在于我曾经在自己的计算机上从 WSL2 中进行。这是我第一次尝试在 Windows Werver 中执行此操作。我认为问题出在launch.json 文件配置中。我不确定如何设置这些参数,也找不到任何解释。我刚刚找到了这个 NodeJS 指南Debugging
    猜你喜欢
    • 2020-09-11
    • 2012-07-14
    • 1970-01-01
    • 2019-07-20
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 2021-06-20
    • 2017-02-11
    相关资源
    最近更新 更多