I'm trying to debug a Symfony app with PhpStorm by following this tutorial: https://gist.github.com/chadrien/c90927ec2d160ffea9c4
I did exactly the same but it does not work well.
php-fpm:
build: ./php
container_name: php-fpm-symfony
links:
- db
ports:
- 9000:9000
- 8448:8448
- 8000:8000
working_dir: /var/www/html/
volumes:
- ../:/var/www/html
volumes_from:
- data
tty: true
env_file:
- ./docker.env
environment:
XDEBUG_CONFIG: remote_host=192.168.0.176
Dockerfile
# XDEBUG
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
When I'm launching the debug with PhpStorm, it seems like the connection is happening. A new window pop up in my browser. My Symfony homepage is here. But it does not stop on my breakpoint. And the step by step debug does not work.
Did I do something wrong?
The other answer is correct that you have to remove the
- 9000:9000
in your ports section.The other issue is that your docker container needs to know the IP address of the docker host. This is so the correct port 9000 is connected to.
Since the release of docker 18.03, you can use the
host.docker.internal
DNS entry in running docker containers.You could just add another echo line to the RUN statement that installs xdebug:
&& echo "xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/xdebug.ini \
Exposing 9000 with docker-for-mac is wrong - you got the direction wrong.
The IDE, PHPstorm, listens on the port 9000, this means, it opens a socket on this 9000, it does not connect to this port.
On the other hand, xdebug connects, attaches, to the port 9000 of, usually, localhost - if it finds a listener, they speak. This, since there is no service on 9000, forwarding the port does not only not make sense, it actually harms you even, since port 9000 will be taken on OSX host localhost, and your PHPstorm will no longer be able listen on it.
What you want to do is
Thats it, it is