我有一个虚拟机在我的系统上运行,它承载了一个apache web服务器和一个php应用程序,我试图通过xdebug进行调试,guest vm使用RedHat virtmanager配置,是一个在qcow2中转换的Hyper-V机器,接口的网络类型是NAT(默认):guest的当前地址是:
192.168.122.78
我尝试了xdebug的各种配置,当前的配置是:
zend_extension=xdebug.so
xdebug.mode = debug
xdebug.client_host = 192.168.122.1
xdebug.client_port = 9003
xdebug.log=/var/www/clients/client1/web4/web/xdebug.log
xdebug.discover_client_host = false
我得到了xdebug。client_host客户端内部运行的IP地址:
$ echo $SSH_CLIENT | awk '{ print $1}'
192.168.122.1
我在Vscode中配置了php-xdebug扩展:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"hostname": "192.168.122.78", --->ip adress of guest machine
"pathMappings": {
"/var/www/clients/client1/web4/web": "${workspaceRoot}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
]
}
但是我得到这个错误
Error: listen EADDRNOTAVAIL: address not available 192.168.122.78:9003
at Server.setupListenHandle [as _listen2] (net.js:1301:21)
at listenInCluster (net.js:1366:12)
at doListen (net.js:1503:7)
at processTicksAndRejections (internal/process/task_queues.js:81:21) {
code: 'EADDRNOTAVAIL',
errno: -99,
syscall: 'listen',
address: '192.168.122.78',
port: 9003
}
据我所知,xdebug调用连接到客户端(我的主机),客户端侦听此端口:如果我尝试telnet并检查端口是否通过客户机的ip地址连接,我将收到一个连接拒绝错误:
$ telnet 192.168.122.78 9003
Trying 192.168.122.78...
telnet: Unable to connect to remote host: Connessione rifiutata
我在服务器上没有任何iptables规则,因为我删除了它们并接受所有传入和传出的连接:
$ iptables -L -v -n
Chain INPUT (policy ACCEPT 329 packets, 28028 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 261 packets, 31104 bytes)
pkts bytes target prot opt in out source destination
这是服务器的xdebug日志:
[1366] Log opened at 2021-10-27 13:32:21.938749
[1366] [Step Debug] INFO: Connecting to configured address/port: 192.168.122.1:9003.
[1366] [Step Debug] WARN: Creating socket for '192.168.122.1:9003', poll success, but error: Operation now in progress (29).
[1366] [Step Debug] ERR: Could not connect to debugging client. Tried: 192.168.122.1:9003 (through xdebug.client_host/xdebug.client_port) :-(
[1366] Log closed at 2021-10-27 13:32:21.940222
显然启用xdebug.discover_client_host = false
不能改变这种情况。
你知道是什么导致了这个问题吗?任何帮助都是感激的。致以最亲切的问候。
我想那是你的问题。那里的hostname": "192.168.122.78",——>主机ip地址
hostname
应该为空,或是Xdebug要将连接到的IP地址。,在你的例子中是192.168.122.1
。