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

PHP 7.2与Xdebug 2.0远程调试配置报错求助

问题分析与修复步骤

核心配置错误

你遇到的EADDRNOTAVAIL错误源于两处关键配置错误:

1. VSCode launch.json 配置错误

你把hostname设成了远程服务器IP(a.b.c.d),但本地调试客户端需要监听本地机器的IP或所有可用接口,本地机器并不持有远程服务器的IP,因此无法完成监听。

修正后的launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "hostname": "0.0.0.0", // 监听本地所有网络接口,也可替换为你的本地内网IP(如192.168.x.x)
            "port": 9000
        }
    ]
}

2. 远程服务器Xdebug配置错误

你将xdebug.remote_host设为127.0.0.1,这指向远程服务器自身的回环地址,Xdebug无法把调试请求发送到你的本地机器。需替换为本地机器的可访问IP:

  • 若远程服务器是云服务器,填写你的本地公网IP;
  • 若二者在同一局域网,填写你的本地内网IP(如192.168.x.x)。

另外注意原始配置中部分参数连写,需拆分换行,修正后的20-xdebug.ini:

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_host=你的本地IP // 替换为实际的本地公网/内网IP
xdebug.remote_log=/var/log/xdebug.log
xdebug.remote_mode=req
xdebug.idekey="vsc"

额外检查项

  • 确认本地9000端口未被占用:Windows用netstat -ano | findstr :9000,Linux/macOS用lsof -i :9000;
  • 本地防火墙开放9000端口,允许远程服务器的入站请求;
  • 验证远程服务器能ping通你的本地IP,确保网络连通;
  • 修改Xdebug配置后,重启远程服务器的PHP服务(如systemctl restart php7.2-fpm或systemctl restart apache2,依Web服务而定)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 19:22:44