VS Code远程调试Turnkey Linux LAMP服务器PHP问题求助
Xdebug 3 + VS Code 远程调试报错 EADDRNOTAVAIL 解决方法
你的核心问题是VS Code的launch.json里hostname配置错误,导致无法绑定端口。以下是具体修正步骤:
1. 修正VS Code的launch.json配置
报错listen EADDRNOTAVAIL: address not available 192.168.20.110:9003的原因是:你让Windows上的VS Code去绑定服务器的IP(192.168.20.110),但这个IP不属于你的Windows电脑,所以绑定失败。
修改方式:
- 把
hostname改成你的Windows电脑的局域网IP(用ipconfig命令查看),或者直接设为"0.0.0.0"(监听本机所有可用IP) - 同时删除
pathMappings里最后一个多余的逗号(JSON语法不允许末尾逗号)
修正后的launch.json:
{ "name": "Listen for Xdebug", "type": "php", "request": "launch", "port": 9003, "hostname": "0.0.0.0", // 替换为你的Windows本机局域网IP也可 "pathMappings": { "/var/websites/test": "${workspaceFolder}/" } }
2. 优化服务器端Xdebug配置(可选但推荐)
服务器上的Xdebug配置可以更精准,避免自动发现客户端IP出错:
- 把
xdebug.discover_client_host=1替换为xdebug.client_host=你的Windows电脑局域网IP - 调试只需要
xdebug.mode=debug即可,develop是开发辅助模式,非必需
修正后的php.ini:
[xdebug] xdebug.mode=debug xdebug.client_host=192.168.20.xxx // 替换为你的Windows电脑IP xdebug.client_port=9003 xdebug.start_with_request=yes
3. 补充网络检查步骤
- 确认服务器能ping通你的Windows电脑IP
- 检查Windows本机防火墙是否允许9003端口入站(之前你只配置了服务器的防火墙,Windows这边也要放行VS Code或者9003端口)
内容的提问来源于stack exchange,提问作者johna
相关产品推荐
相关产品推荐

