- For your local dev, create a
Dockerfilethat is based on your production image and simply installxdebuginto it. Exemple:
FROM php:5
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
- Get you local IP address (
ifconfigor such) - Start your container with the following environment variable:
XDEBUG_CONFIG="remote_host={{YOUR_IP_ADDRESS}}"
-
Simple
dockerrun:docker run -e XDEBUG_CONFIG="remote_host={{YOUR_IP_ADDRESS}}" your-image -
With
docker-compose:# docker-compose.yml foo: build: path/to/Dockerfile environment: XDEBUG_CONFIG: remote_host={{YOUR_IP_ADDRESS}}
- In Intellij/PHPStorm go to:
Languages & Frameworks>PHP>Debug>DBGp Proxyand set the following settings:
Host: your IP addressPort: 9000
Then you're all set and can start listening for PHP Debug connections from your IDE. On the first run it will ask you to map
your local directoryies to the docker directories, but after that nothing will be required anymore!
Happy debugging!

Tested the performance when listening and when not listening. Both times it lasted 2-3 seconds on my machine. So that is not optimal, probably it works always with xdebug mode even when turning off listening in php storm.
Would be good to find a quick way to turn xdebug off.
I tried commenting this line
#COPY xdebug.ini /etc/php/7.0/mods-available/xdebug.iniand rebuild
docker-compose build.And executed again. But still same those 2-3 seconds. So not sure what is causing this. Maybe thats is not xdebug, need to try.
Interesging - tried same script on php 7.1 where I have setup without docker. When turning on listening in phpstorm, then it loads in 4-5 seconds. When turning off - 2-3 seconds. So how in this docker setup it has constantly 2-3 seconds?