use*_*186 0 php xdebug docker visual-studio-code
我正在尝试对 Ubuntu 上的 Docker/PHP-Xdebug/VSCode 环境进行故障排除,该环境在过去几个月中一直运行良好。现在 xdebug 连接到客户端时遇到问题。
进入 Docker 后docker exec --tty --interactive bw bash
php -v
Run Code Online (Sandbox Code Playgroud)
回报
PHP 7.2.14 (cli) (built: Feb 6 2019 05:10:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
Run Code Online (Sandbox Code Playgroud)
whilephp -m -c在 [Zend Modules] 部分列出了 Xdebug。
这是 .ini 部分
[xdebug]
xdebug.default_enable = 1
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.idekey = VSCODE
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
xdebug.remote_log=/var/log/apache2/xdebug.log
xdebug.remote_timeout = 500
Run Code Online (Sandbox Code Playgroud)
其中的所有内容都会相应地反映在phpinfo()输出中。
docker-compose.yml
version: "3.1"
services:
webserver:
build: docker/apache
container_name: bw
volumes:
- .:/var/www/html
ports:
- "8000:80"
expose:
- "9000"
restart: always
Run Code Online (Sandbox Code Playgroud)
启动.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log":true,
"pathMappings": {
"/var/www/html": "${workspaceRoot}/",
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
} ]
}
Run Code Online (Sandbox Code Playgroud)
这是 xdebug.log 的尾部
[156] Log opened at 2019-08-05 19:39:58
[156] I: Checking remote connect back address.
[156] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[156] I: Checking header 'REMOTE_ADDR'.
[156] I: Remote address found, connecting to 172.18.0.1:9000.
[156] E: Time-out connecting to client (Waited: 500 ms). :-(
[156] Log closed at 2019-08-05 19:39:59
Run Code Online (Sandbox Code Playgroud)
我强烈怀疑我缺乏 Docker 知识是使这项工作再次发挥作用的问题。
任何帮助,将不胜感激。
问题出在主机的防火墙上。无法真正说出该规则如何/为何消失。
我以错误的方式使用 telnet 探测端口,这让我认为防火墙允许流量通过。
ufw allow from any to any port 9000 proto tcp事实上,主机确实重新建立了一切。