首页 > 解决方案 > VS Code launch.json Xdebug 配置,用于在 Windows Server 8 中逐步调试 PHP 页面

问题描述

我在 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

考虑到:

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

我还在 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()函数输出:

Xdebug 输出 1/3
Xdebug 输出 2/3
Xdebug 输出 3/3

标签: phpxdebugremote-debuggingvscode-debuggervscode-remote

解决方案


我认为你的问题是:

xdebug.remote_port = 9003

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

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

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

提示

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


推荐阅读