我安装了visual studio代码1.41.1和PHP调试版本- 1.13.0。
https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
我在Ubuntu上运行PHP Lamp stack,我的PHP信息显示“xdebug xdebug support enabled Version 2.9.0”
我的PHP.ini配置如下:
[XDebug]
zend_extension = /usr/lib/php/20170718/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_handler = dbgp
;xdebug.remote_host = 192.168.1.103
xdebug.remote_port=9000
xdebug.remote_log=/var/log/xdebug.log我的launch.json如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"hostname": "192.168.1.23"
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000,
"hostname": "192.168.1.23"
}
]
}我的服务器运行在192.168.1.23上,我的ide运行在192.168.1.103上。
当我尝试‘监听XDebug’或‘启动当前打开的脚本’时,我得到以下错误:
Error: listen EADDRNOTAVAIL: address not available 192.168.1.23:9000
at Server.setupListenHandle [as _listen2] (net.js:1209:19)
at listenInCluster (net.js:1274:12)
at doListen (net.js:1413:7)
at processTicksAndRejections (internal/process/task_queues.js:84:9) {
code: 'EADDRNOTAVAIL',
errno: 'EADDRNOTAVAIL',
syscall: 'listen',
address: '192.168.1.23',
port: 9000
}我尝试将xdebug.remote_connect_back设置为0和1,并使用xdebug.remote_host = 192.168.1.103显式指定远程主机IP或将其注释掉
在Visual Studio中,该错误几乎会立即触发,这将表明它在本地被阻止。
查看我的日志文件: xdebug.log:
[2268] Log opened at 2020-01-08 12:39:09
[2268] I: Connecting to configured address/port: 192.168.1.103:9000.
[2268] E: Time-out connecting to client (Waited: 200 ms). :-(
[2268] Log closed at 2020-01-08 12:39:09
[2225] Log opened at 2020-01-08 13:09:37
[2225] I: Checking remote connect back address.
[2225] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[2225] I: Checking header 'REMOTE_ADDR'.
[2225] W: Remote address not found, connecting to configured address/port: localhost:9000. :$
[2225] W: Creating socket for 'localhost:9000', poll success, but error: Operation now in pr$
[2225] E: Could not connect to client. :-(
[2225] Log closed at 2020-01-08 13:09:37日志文件似乎写得很慢-我不确定是哪个事件触发了日志中的事件。我怀疑它是直接从我的远程主机访问网页,而不是通过Visual Studio代码。
我还将我的windows defender防火墙设置为在端口9000上打开。
基于注释的编辑。192.168.1.103是运行visual studio代码的windows 10计算机的IP地址。该机器还运行版本6.0.8 r130520 (Qt5.6.2),虚拟机的IP地址为192.168.1.23。
我已将超时时间更新为2000毫秒。
我观察到,如果我关闭虚拟机,VSC会尝试连接,并且尝试连接的时间会更长。然而,当虚拟机启动时,它会立即出错。哪种情况表明虚拟机阻塞了该端口?
最后-是什么触发了进入xdebug.log。简单地在网站上加载PHP文件触发器会输出记录器吗?我问的原因是我无法识别触发错误,但打开时间增量之间的日志文件,即今天与昨晚,是否产生了各种错误?
机器和虚拟机在基于路由器的防火墙后面都是安全的,所以这不会是外部流量。
虚拟机如预期的那样在Windows10客户机上运行。只是连接调试器失败。但是PHP/MYSQL/ APACHE都运行正常。
发布于 2020-02-04 01:55:19
该问题与防火墙阻止传入连接有关。我通过以下几个步骤解决了这个问题:
安装UFW -
sudo apt-get install ufw
sudo ufw enable
sudo ufw allow 9000/tcp在我的Php.ini中,我使用以下设置:
[dDebug]
zend_extension = /usr/lib/php/20190902/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_port=9000最后,我的启动Json有以下内容:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html/YourApp": "${workspaceRoot}/"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}JSON假设工作空间指向源数据的根目录,而不是隐藏在子文件夹中。
最后,您需要添加UFW规则以远程访问您的web服务器,因为这些规则在安装后默认不会出现在UFW中
sudo ufw app list
sudo ufw allow 'Apache Full'我还使用该方法从我的应用程序列表中添加了其他规则。
我希望这对像我这样正在努力连接到新启动的Ubuntu18.04.4VM上的xDebug的人有所帮助。
发布于 2020-01-08 22:01:57
看起来其他东西已经在监听端口9000,因此,VS也不能打开相同的端口进行监听。这很可能是PHP-FPM。
要解决此问题,请在php.ini中改为设置以下内容:
xdebug.remote_port=9003并将VS配置(两次)更改为同一端口:
"port": 9003,https://stackoverflow.com/questions/59647056
复制相似问题