首页 > 解决方案 > 带有 XDebug 和 PHP Debug 扩展以及 IISExpress 的 VSCode 和 PHP

问题描述

我正在尝试在 VS Code 中使用 PHP Debug 扩展。我已按照说明将 phpinfo 内容粘贴到向导中并下载了相应的 dll。我收到以下错误

启动.json

"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "log": true
        },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000
    }
]

php.ini

[XDEBUG]
zend_extension = C:\PHP\ext\php_xdebug-2.9.6-7.4-vc15-nts.dll
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9000
xdebug.remote_mode = req

如果我选择了之前启动 IISExpress 的监听选项,我会收到此错误

错误:在 Server.listen (net.js:1364) 的listenInCluster (net.js:1276:12) 处侦听 EACCES:Server.setupListenHandle [as _listen2] (net.js:1211:19) 的权限被拒绝 0.0.0.0:9000 :7) 在 c:\Users\me.vscode\extensions\felixfbecker.php-debug-1.13.0\out\phpDebug.js:236:24 at new Promise () at createServer (c:\Users\me.vscode \extensions\felixfbecker.php-debug-1.13.0\out\phpDebug.js:184:40) 在 PhpDebugSession。(c:\Users\me.vscode\extensions\felixfbecker.php-debug-1.13.0\out\phpDebug.js:240:27) 在 Generator.next () 在 c:\Users\me.vscode\extensions\ felixfbecker.php-debug-1.13.0\out\phpDebug.js:7:71 at new Promise () { code: 'EACCES', errno: 'EACCES', syscall: 'listen', address: '0.0.0.0' ,端口:9000 }

如果我选择其他选项并先启动 VS Code,则会收到 IISExpress 错误

无法为站点“XXXXXXX-0f34f450-230f-4d11-8878-1a90a024dcf6”应用程序“/”注册 URL“http://localhost:9000/”。错误描述:该进程无法访问该文件,因为它正被另一个进程使用。(0x80070020)

我知道没有使用端口 9000,因为如果我在没有运行的情况下运行此命令,它会显示没有运行

Get-Process -Id (Get-NetTCPConnection -LocalPort 9000).OwningProcess

显然双方都可以启动端口 9000,但他们不乐意共享同一个端口。我错过了什么?

标签: phpvisual-studio-codexdebugiis-express

解决方案


我的错误是该站点也在端口 9000 上运行。它需要与 XDebug 完全不同的端口,它在自己的端口上侦听。

iisexpress.json

{
  "port": 1785,
  "path": "C:\\YourSite",
  "clr": "v4.0",
  "protocol": "http"
}

推荐阅读