Xdebug (inside a Docker container) ignoring the XDEBUG_CONFIG environment variable

I am running a PHP application on Docker and I would like to debug it using XDebug. In my docker compilation, I added the following lines in the phpfpm part:

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 have configured PHPStorm correctly, listening on port 9000 and running the application.

The app works flawlessly, but XDebug doesn't seem to work.

If I move the config lines inside the php.ini file, the debugger works, except the server name is empty and I can't debug (which is why I tried to follow the docker config path).

If, inside a docker container, I run echo $ XDEBUG_CONFIG, the output is correct, but XDebug doesn't seem to read that Env variable.

+3


source to share


3 answers


I had the same problem. Image was based on nimmis/alpine-apache-php7/

. I found that the image starts processes supervisor

. supervisor

doesn't know the Docker environment variables.

Agreeing to tell a supervisor

process to be started is to create a run

script in /etc/sv/{process}/run

. A script like this one was used to start Apache. I needed to change the script so that it would import the Docker environment variables before starting Apache.

The docs for the base image explain the Docker environment import convention:

If you need environment variables from docker command line (-e, - env ​​= []) add

source /etc/envvars

before using them in your script file



So, I created my own run

script
for Apache - I added source /etc/envvars

just before execution httpd

.

I have overwritten the original run

script
by adding a simple one COPY

to my Dockerfile :

COPY apache-run.sh /etc/sv/apache2/run

      

This successfully ensured that mine $XDEBUG_CONFIG

was visible at httpd

the time it was launched. I was able to confirm that this affected my PHP configuration by typing phpinfo();

on the webpage.

+2


source


Are you done phpinfo();

? This should tell you the settings to use.

I had the same problem ... took me forever to understand. Are you using xdebug.remote_connect_back=1

? If remove this line.



My nginx proxy was forwarding IP (which was wrong), so the ip set in XDEBUG_CONFIG was ignored.

0


source


For me it was a different issue using the official PHP-FPM-Alpine ( FROM php:7-fpm-alpine

) docker image

I needed to add XDEBUG-CONFIG to the fpm pool config: env[XDEBUG_CONFIG] = $XDEBUG_CONFIG

See full config https://github.com/attrib/docker-symfony

0


source







All Articles