[英]Xdebug (inside Docker container) ignoring XDEBUG_CONFIG environment variable
I'm running a PHP application on Docker and I'd like to debug it using XDebug. 我在Docker上运行PHP应用程序,我想使用XDebug进行调试。 In my docker-compose I added the following lines in the phpfpm part: 在我的docker-compose中,我在phpfpm部分添加了以下行:
environment:
XDEBUG_CONFIG: "remote_enable=1 remote_host=192.168.110.29 remote_port=9000 idekey=PHPSTORM remote_autostart=1"
PHP_IDE_CONFIG: "serverName=reports.dev"
I configured PHPStorm in the right way, listening on port 9000 and ran the application. 我以正确的方式配置PHPStorm,侦听端口9000并运行应用程序。
The application works flawlessly but XDebug doesn't seem to be working. 该应用程序完美无缺,但XDebug似乎没有工作。
If I move the lines of configuration inside the php.ini file the debugger works, except for the fact that Server Name is empty and I cannot debug (that's why I tried following the docker-compose configuration way). 如果我移动php.ini文件中的配置行调试器工作,除了服务器名称为空并且我无法调试的事实(这就是为什么我尝试遵循docker-compose配置方式)。
If, inside the docker container, I run echo $XDEBUG_CONFIG the output is right, but XDebug seems not to read that Env variable. 如果,在docker容器内,我运行echo $ XDEBUG_CONFIG输出是正确的,但是XDebug似乎没有读取那个Env变量。
I had the same problem. 我有同样的问题。 My image was based on nimmis/alpine-apache-php7/
. 我的图片基于nimmis/alpine-apache-php7/
。 I found that the image was using supervisor
to start processes. 我发现图像是使用supervisor
启动进程。 supervisor
has no knowledge of the Docker environment variables. supervisor
不了解Docker环境变量。
The convention to tell supervisor
that a process needs to be run, is to create a run
script at /etc/sv/{process}/run
. 告诉supervisor
需要运行进程的惯例是在/etc/sv/{process}/run
创建run
脚本。 A script like this was used to start Apache. 像这样的脚本用于启动Apache。 I needed to change the script so that it would import Docker environment variables before starting Apache. 我需要更改脚本,以便在启动Apache之前导入Docker环境变量。
The docs for the base image explain the convention for importing Docker environment: 基本映像的文档解释了导入Docker环境的约定:
If you need environment variables from the docker command line (-e,--env=[]) add 如果需要来自docker命令行的环境变量(-e, - env = [])add
source /etc/envvars
before you use them in the script file 在脚本文件中使用它们之前
So I created my own custom run
script for Apache — I added source /etc/envvars
just before execution of httpd
. 所以我为Apache创建了自己的自定义run
脚本 - 我在执行httpd
之前添加了source /etc/envvars
。
I overwrote the original run
script , by adding a simple COPY
to my Dockerfile : 我通过在我的Dockerfile中添加一个简单的COPY
来覆盖原始的run
脚本 :
COPY apache-run.sh /etc/sv/apache2/run
This successfully ensured that my $XDEBUG_CONFIG
was visible to httpd
at the time it was launched. 这成功地确保了我的$XDEBUG_CONFIG
在启动时对httpd
可见。 I was able to confirm that this affected my PHP configuration, by printing phpinfo();
通过打印phpinfo();
我能够确认这会影响我的PHP配置phpinfo();
in a webpage. 在网页中。
Did you do a phpinfo();
你做过phpinfo();
? ? That should tell you the settings used. 这应该告诉你使用的设置。
I had the same problem... took me forever to figure out. 我有同样的问题......带我永远弄明白。 Are you using xdebug.remote_connect_back=1
? 你使用的是xdebug.remote_connect_back=1
吗? If so remove that line. 如果是这样,删除该行。
My nginx proxy was forwarding an IP through (which was wrong) and so the ip set in XDEBUG_CONFIG was being ignored. 我的nginx代理正在转发IP(这是错误的),所以XDEBUG_CONFIG中的ip设置被忽略了。
For me it was a different problem using the official PHP-FPM-Alpine docker image ( FROM php:7-fpm-alpine
) 对我来说,使用官方的PHP-FPM-Alpine docker图像是一个不同的问题( FROM php:7-fpm-alpine
)
I needed to add the XDEBUG-CONFIG to the fpm pool config: env[XDEBUG_CONFIG] = $XDEBUG_CONFIG
我需要将XDEBUG-CONFIG添加到fpm池配置中: env[XDEBUG_CONFIG] = $XDEBUG_CONFIG
See full config https://github.com/attrib/docker-symfony 请参阅完整配置https://github.com/attrib/docker-symfony
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.