[英]Using Xdebug and PhpStorm with Docker container on Windows
我正在尝试使用 PhpStorm 使 Xdebug 为 Windows 上的 Docker 容器工作。 我阅读了不同的文章和其他主题,但仍然无法正常工作。
在 docker-compose.yaml 内部,我的应用程序容器具有以下配置:
version: "3.7"
services:
#PHP Service
app:
build:
args:
user: user
uid: 1000
context: ./
dockerfile: docker/php/Dockerfile
image: rpg
container_name: rpg-app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
PHP_IDE_CONFIG: serverName=RpgServer
working_dir: /var/www
command: /var/www/docker/php/application-init.sh
volumes:
- ./:/var/www
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- rpg-app-network
depends_on:
- db
...
#Nginx Service
nginx:
image: nginx:1.17-alpine
container_name: rpg-nginx
restart: unless-stopped
tty: true
ports:
- "8080:80"
- "443:443"
volumes:
- ./:/var/www
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- rpg-app-network
depends_on:
- app
我有以下 PhpStorm 配置:
我使用 Chrome 的 Xdebug Helper 插件发送 session 密钥
在phpinfo()
我可以看到 PHP 收到 Xdebug session 密钥:
我正在 PhpStorm 中监听 Xdebug 连接(在整个代码中都有断点):
我在启用了 Xdebug Helper 的浏览器中运行应用程序。
然而。 断点没有阻塞,也没有对 PhpStorm 的回调。
感谢LazyOne的帮助,我再次查看了配置,发现 Step Debugger 已禁用。
我在我的 php-fpm Dockerfile 中以以下方式安装 Xdebug:
# Install xdebug
RUN pecl install xdebug && docker-php-ext-enable xdebug
这是我原来的 Xdebug 配置:
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
xdebug.remote_log=/var/www/storage/logs/xdebug.log
xdebug.remote_mode = req
我添加了
xdebug.mode = debug
重新运行docker-compose up
我开始在容器日志中收到通知:
rpg-app | NOTICE: PHP message: Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
我发现这个线程Xdebug: [Step Debug] 无法连接到调试客户端
并补充说:
xdebug.client_host=host.docker.internal
xdebug.client_port=9001
得到:
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
xdebug.remote_log=/var/www/storage/logs/xdebug.log
xdebug.remote_mode = req
xdebug.mode = debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9001
现在一切正常::)
编辑:根据 LazyOne 的评论,我更新到 Xdebug v3 配置设置。 结果是:
[xdebug]
xdebug.idekey=PHPSTORM
xdebug.mode = debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9001
xdebug.log=/var/www/storage/logs/xdebug.logs
从外观上看,除了源路径映射(您可以在 PHPStorm 的服务器下找到它)之外,您已经正确设置了所有内容。 这通常是断点不起作用的原因。 还尝试启用“在第一行中断”选项。
除非您真的需要 docker 组合来运输,否则我强烈建议您使用Lando 。 它始终具有正确的 XDebug 配置,并且具有可使用的真实 (https) URL 有很大帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.