gpt4 book ai didi

php - Docker Compose 和 Xdebug 在 PhpStorm 中不起作用

转载 作者:行者123 更新时间:2023-12-02 20:56:47 25 4
gpt4 key购买 nike

我已经尝试了很多尝试让 Xdebug 在 Docker 容器中工作。我接触到了这些资源:

我认为问题要么出在我不理解的端口上,要么出在调试器 session 未启动或未被识别的问题上。对于调试器 session ,我还尝试安装一个设置 cookie 的浏览器扩展。

我最终至少有了单独的容器,一个作为启用了 Xdebug 的开发容器。

docker-compose.yml

version: "3"
services:
production:
build: .
ports:
- "8000:80"
volumes:
- .:/var/www/html
development:
build: .
ports:
- "8080:80"
# - "10000:80" also not working
volumes:
- .:/var/www/html
- ./dev.php.ini:/usr/local/etc/php/php.ini

Dockerfile

FROM php:7.4.0-apache

RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

dev.php.ini

xdebug.remote_enable=on
xdebug.remote_host=host.docker.internal
xdebug.remote_port=10000
xdebug.idekey=PHPSTORM

localhost:8080 phpinfo数据

enter image description here

enter image description here

PhpStorm 配置

enter image description here

有什么想法吗?

最佳答案

在启动我的机器以根据@abestrad 和@LazyOne 的评论进一步调查后,不做任何更改,打开 localhost:8080 突然让调试工作停止在我设置的断点处。其实我在写这个问题之前就已经尝试过重启Docker Desktop App了,可能那个时候我的配置是错误的。

但最终解决方案是:重新启动 PC

注意

可以肯定的是,我也尝试在私有(private)浏览器 session 中打开它,但它不再工作了。那是因为特殊的 cookie 仍然设置在普通的浏览器存储中(cookie 存储在我已经卸载的浏览器扩展中,或者在写问题之前试用 JetBrains Bookmarklets generator)。

让它每次都能工作的解决方案是添加以下内容:

xdebug.remote_autostart=1

引用自here :

Normally you need to use a specific HTTP GET/POST variable to start remote debugging (see Step Debugging). When this setting is set to 1, Xdebug will always attempt to start a remote debugging session and try to connect to a client, even if the GET/POST/COOKIE variable was not present.

关于php - Docker Compose 和 Xdebug 在 PhpStorm 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62486126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com