How can I use XDebug with a PHP upstream behind an nginx reverse proxy? How can I use XDebug with a PHP upstream behind an nginx reverse proxy? docker docker

How can I use XDebug with a PHP upstream behind an nginx reverse proxy?


Here's how I got PHP Storm to connect to a dockerized php-fpm / nginx application:

Inject the remote host IP into the container. In your host, set the variable:

XDEBUG_HOST=$(ipconfig getifaddr en0)

I'm not too familiar with docker-compose. I'm using a Kubernetes manifest, but I'm sure there's a way to inject environment variables.

in xdebug.ini:

xdebug.remote_host=${XDEBUG_HOST}

Now you should be able to set up your xdebug client to listen on xdebug.remote_port for debug connections. You'll also have to set up a debug server in PHP Storm or whatever IDE you're using that points to http://127.0.0.1:8080 (or whatever port you're port-forwarding the nginx container to).

Here's what my setup looks like. I'm using PHP Storm but I'm sure you can adapt this to other xdebug clients.

PHP Storm Xdebug server settings

PHP Storm preferences

xdebug.ini:

zend_extension=xdebug.soxdebug.remote_enable=1xdebug.remote_port=10000xdebug.remote_autostart=1xdebug.idekey=www-dataxdebug.remote_host=${XDEBUG_HOST}

Reference: https://shippingdocker.com/xdebug/


Being on windows I needed to disable also the option remote_connect_back (on linux it was not needed though)

xdebug.remote_connect_back = 0xdebug.remote_host = host.docker.internal