2

Trying to debug PHP from IntelliJ on Windows 10.

These are the first lines in my Dockerfile:

FROM drupaldocker/php:7.1-apache

# Install xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug

I tried copying and pasting configuration from several sources, e.g.:

&& echo "error_reporting = E_ALL" > /usr/local/etc/php/php.ini \
&& echo "display_startup_errors = On" >> /usr/local/etc/php/php.ini \
&& echo "display_errors = On" >> /usr/local/etc/php/php.ini \
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

The result is always the same.

I start the container via docker-compose and map port 9000 to localhost:9000 using the following line in compose yml.

ports:
    - "9000:9000"

When I try to start listening from IntelliJ I get the error: Port 9000 is busy.

I tried telnet 127.0.0.1 9000 I get the message: connection closed by foreign host.

Any idea what could be wrong?

Bishoy
  • 705
  • 9
  • 24
  • See if this helps http://tarunlalwani.com/post/debugging-php-xdebug-docker/ – Tarun Lalwani Sep 24 '17 at 04:53
  • 1
    1) *"I start the container and map port 9000 to localhost:9000"* WHY? It's xdebug that connect to IDE and not other way around ... so why opening it in Docker? (please read the *xdebug basics*) 2) Why do you have 2 different occurrences of `xdebug.remote_connect_back` rule? 3) BTW -- `remote_connect_back` most likely will not work and you will need to specify the `remote_host` manually (the IP where IntelliJ is running). 4) https://stackoverflow.com/q/44032296/783119 .. or the link that TarunLalwani provided – LazyOne Sep 24 '17 at 10:59
  • >> _"I start the container and map port 9000 to localhost:9000"_ please describe how you map the ports (I think the problem is somewhere here) – alek13 Sep 24 '17 at 11:01
  • You need to connect form inside of a Docker (from xDebug) to localhost:9000 (to server upped by IntelliJ): https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach . Also see links in comments above. – alek13 Sep 24 '17 at 11:10
  • edited to add the lines of compose yml that I've used to map ports – Bishoy Sep 24 '17 at 11:23
  • I tried `99-xdebug.ini` from the link in Tarun's comment but got the same result. I didn't try the rest of the steps because I don't have FPM nor Nginx. Do I need `app.config`? what does it do? – Bishoy Sep 24 '17 at 11:29
  • it worked after removing the port mapping, and specifying the IP address of my pc (the host for docker) in the `xdebug.remote_host` as suggested by LazyOne. Anyone knows a way that make `remote_connect_back` work so that I don't need to specify the IP address? – Bishoy Sep 25 '17 at 13:21

0 Answers0