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
相关产品推荐
相关产品推荐

