You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Win10下Xdebug3+PHP+VS Code调试时浏览器无法正常显示,求解决办法

解决VS Code中PHP内置Web服务器"Not Found"问题

原因分析

VS Code的"launch built-in web server"默认以当前工作区根目录作为内置服务器的根目录,且默认寻找index.php作为入口文件。如果测试脚本不是index.php,或者VS Code未正确识别工作区根目录,就会出现资源找不到的错误。

修复步骤

1. 确认工作区设置

  • 打开VS Code时,确保你打开的是包含PHP脚本的文件夹作为工作区(而非单独打开单个文件)。仅打开单个文件时,内置服务器的根目录可能与脚本所在目录不符,导致访问根路径找不到文件。

2. 配置launch.json指定入口或根目录

  • 打开调试面板(Ctrl+Shift+D),点击"创建launch.json文件"并选择"PHP"环境。
  • 在生成的launch.json中修改"Launch Built-in Web Server"配置:
    若要指定单个脚本作为入口,添加runtimeArgs:
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch Built-in Web Server",
                "type": "php",
                "request": "launch",
                "runtimeArgs": [
                    "-S",
                    "localhost:0",
                    "你的脚本文件名.php" // 替换为实际要运行的脚本,比如test.php
                ],
                "port": 0,
                "serverReadyAction": {
                    "action": "openExternally",
                    "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started"
                }
            }
        ]
    }
    
    若要以当前文件夹为服务器根目录(自动识别index.php),则配置:
    "runtimeArgs": [
        "-S",
        "localhost:0",
        "-t",
        "${workspaceRoot}"
    ]
    

3. 手动访问具体脚本路径

如果不想修改配置,当Chrome打开http://localhost:62xxx/后,手动在URL末尾添加脚本文件名,比如http://localhost:62xxx/test.php,即可直接查看脚本输出。

4. 验证Xdebug调试配置

确保php.ini中Xdebug的远程调试参数正确,保证内置服务器下调试功能正常:

xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = localhost
xdebug.client_port = 9003

修改后重启Apache和VS Code即可。


内容的提问来源于stack exchange,提问作者jxm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 00:05:24