Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker + xdebug + Atom: Breakpoints won't fire

I know there are many questions like this one out there. Unfortunately, none of those answers worked for me.

Environment:

  • Host OS: macOS Sierra 10.12.6
  • IDE: Atom (1.19.3) with php-debug (0.2.5) extension
  • php-debug settings: listen on 127.0.0.1:9000, otherwise default settings

Dockerfile:

FROM php:7.0-apache
RUN apt-get update \
    && apt-get install -y \
        net-tools \
    && pecl install \
        xdebug-2.5.0 \
    && docker-php-ext-enable \
        xdebug \
    && echo "ServerName localhost" >> /etc/apache2/apache2.conf \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_log=/var/log/xdebug.log" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    # && echo "xdebug.remote_host=172.17.0.1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.idekey=xdebug-atom" >> /usr/local/etc/php/conf.d/xdebug.ini

src/index.php:

<?php
var_dump($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']); // <-- breakpoint is set at this line. However, does not fire in IDE. var_dump() output: null, 172.17.0.1
xdebug_break(); // function is recognized, however, does not have any effect
phpinfo();

Command to startup container:

$ docker build -t xdebug . && docker run -d -p 80:80 -v /path/to/project/src/:/var/www/html/ --name xdebug_container xdebug

Outcome when calling "localhost" in browser:

  • Breakpoint does not fire in IDE, browser does not halt call, instead regularily loads page.
  • Page shows formatted var_dump() in xdebug-style.
  • phpinfo() shows xdebug section with expected settings as in Dockerfile
  • Wireshark shows there is no communication going on between docker container and host on port 9000.
  • /var/log/xdebug.log does not exist in container. So no information here.
  • $ netstat -anp does not show any problems with port 9000 inside the container
  • The container is able to ping the host using 172.17.0.1.

Variations I've tried:

  • no xdebug.idekey specified
  • xdebug.remote_connect_back=0 and xdebug.remote_host with local host IP and 127.0.0.1
  • tried no pathmapping and pathmapping: /var/www/html;/path/to/project/src
  • not setting a ServerName

Background info: php-debug works fine with MAMP Pro's xdebug

phpinfo xdebug section:

xdebug support  enabled
Version 2.5.0
IDE Key xdebug-atom
Supported protocols Revision
DBGp - Common DeBuGger Protocol $Revision: 1.145 $
Directive   Local Value Master Value
xdebug.auto_trace   Off Off
xdebug.cli_color    0   0
xdebug.collect_assignments  Off Off
xdebug.collect_includes On  On
xdebug.collect_params   0   0
xdebug.collect_return   Off Off
xdebug.collect_vars Off Off
xdebug.coverage_enable  On  On
xdebug.default_enable   On  On
xdebug.dump.COOKIE  no value    no value
xdebug.dump.ENV no value    no value
xdebug.dump.FILES   no value    no value
xdebug.dump.GET no value    no value
xdebug.dump.POST    no value    no value
xdebug.dump.REQUEST no value    no value
xdebug.dump.SERVER  no value    no value
xdebug.dump.SESSION no value    no value
xdebug.dump_globals On  On
xdebug.dump_once    On  On
xdebug.dump_undefined   Off Off
xdebug.extended_info    On  On
xdebug.file_link_format no value    no value
xdebug.force_display_errors Off Off
xdebug.force_error_reporting    0   0
xdebug.halt_level   0   0
xdebug.idekey   xdebug-atom xdebug-atom
xdebug.max_nesting_level    256 256
xdebug.max_stack_frames -1  -1
xdebug.overload_var_dump    2   2
xdebug.profiler_aggregate   Off Off
xdebug.profiler_append  Off Off
xdebug.profiler_enable  Off Off
xdebug.profiler_enable_trigger  Off Off
xdebug.profiler_enable_trigger_value    no value    no value
xdebug.profiler_output_dir  /tmp    /tmp
xdebug.profiler_output_name cachegrind.out.%p   cachegrind.out.%p
xdebug.remote_addr_header   no value    no value
xdebug.remote_autostart On  On
xdebug.remote_connect_back  On  On
xdebug.remote_cookie_expire_time    3600    3600
xdebug.remote_enable    On  On
xdebug.remote_handler   dbgp    dbgp
xdebug.remote_host  localhost   localhost
xdebug.remote_log   /var/log/xdebug.log /var/log/xdebug.log
xdebug.remote_mode  req req
xdebug.remote_port  9000    9000
xdebug.scream   Off Off
xdebug.show_error_trace Off Off
xdebug.show_exception_trace Off Off
xdebug.show_local_vars  Off Off
xdebug.show_mem_delta   Off Off
xdebug.trace_enable_trigger Off Off
xdebug.trace_enable_trigger_value   no value    no value
xdebug.trace_format 0   0
xdebug.trace_options    0   0
xdebug.trace_output_dir /tmp    /tmp
xdebug.trace_output_name    trace.%c    trace.%c
xdebug.var_display_max_children 128 128
xdebug.var_display_max_data 512 512
xdebug.var_display_max_depth    3   3

Does anybody have an idea how to handle or debug this issue?

UPDATE:

I deactivated xdebug.remote_connect_back and set xdebug.remote_host to my host's private IP. Now there is a connection visible in Wireshark on the host. However, the container's TCP [SYN] is followed by a TCP [RST, ACK] by the host. Seems like Atom does not accept the connection.

like image 620
23785623985 Avatar asked Jan 30 '26 05:01

23785623985


1 Answers

After some cumbersome debugging I found the answer myself:

The basic problem was that container and host settings did not match exactly.

Settings in Atom's php-debug on the host:

  • set IP to your local IP (NOT 127.0.0.1!)
  • setup path mapping

On the container (=Dockerfile):

  • don't set an xdebug.idekey
  • deactivate xdebug.remote_connect_back
  • set your local IP (the one you used in Atom's settings) as xdebug.remote_host
  • deactivate "docker-php-ext-enable xdebug"
like image 95
23785623985 Avatar answered Feb 01 '26 17:02

23785623985



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!