- For your local dev, create a
Dockerfile
that is based on your production image and simply installxdebug
into 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 (
ifconfig
or such) - Start your container with the following environment variable:
XDEBUG_CONFIG="remote_host={{YOUR_IP_ADDRESS}}"
-
Simple
docker
run: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 Proxy
and 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!
FINALLY :)
This is how i solved this using Mac Sierra, Docker Native Version 1.12.1, PhpStorm 2016.3 EAP, https://github.com/shincoder/homestead-docker:
n provision.sh
Enable Remote xdebug
echo "xdebug.idekey = PHPSTORM" >> /etc/php/7.0/fpm/conf.d/20-xdebug.ini
echo "xdebug.default_enable = 0" >> /etc/php/7.0/fpm/conf.d/20-xdebug.ini
echo "xdebug.remote_enable = 1" >> /etc/php/7.0/fpm/conf.d/20-xdebug.ini
echo "xdebug.remote_autostart = 0" >> /etc/php/7.0/fpm/conf.d/20-xdebug.ini
echo "xdebug.remote_connect_back = 0" >> /etc/php/7.0/fpm/conf.d/20-xdebug.ini
echo "xdebug.profiler_enable = 0" >> /etc/php/7.0/fpm/conf.d/20-xdebug.ini
echo "xdebug.remote_host = 10.254.254.254" >> /etc/php/7.0/fpm/conf.d/20-xdebug.ini
in docker-compose.yml
expose:
- "9000"
ports:
- "8080:80" # web
- "2222:22" # ssh
- "35729:35729" # live reload
- "9876:9876" # karma server
environment:
PHP_XDEBUG_ENABLED: 1 # Set 1 to enable.
XDEBUG_CONFIG: remote_host=10.254.254.254
The IP i used everywhere is for my local mac, the one with phpStorm installed on. The IP is not 10.254.254.254 but since the IP could change i made an alias that points to 127.0.0.1.
For some reason i didn't work with 127.0.0.1 in all settings, i guess Docker container sees it at it self?
Anyway, to create the alias i did:
sudo ifconfig en0 alias 10.254.254.254 255.255.255.0
in phpStorm i used all default settings but added this: