PHPStorm doesn't work with Docker and XDebug

Hi,

I have a magento project set up in a docker-compose with two services: php-apache7.2 and mariadb10.1.36
This is working fine so far.

Now I set this up in PHPStom as a local webserver (because it's running on 127.0.0.1:80 and the sourcecode is mounted as a volume)
This also seems to work so far.

Now as the last thing I tried to set up Xdebug, which isn't working.
When I go to Preferences -> PHP > Debug and Validate the debugger configuration (as a local web server) this works and gives me the following output:

I also installed the browser extension for chrome.
Now when I activate this extension and set phpstorm to listen for incoming php debug connections and set a few breakpoints, when I reload the page nothing happens.


My settings look like this:

This is the output of my phpinfo

xdebug support enabled
Version 2.6.0
IDE Key PHPSTORM
Supported protocols
DBGp - Common DeBuGger Protocol
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.filename_format no value no value
xdebug.force_display_errors Off Off
xdebug.force_error_reporting 0 0
xdebug.gc_stats_enable Off Off
xdebug.gc_stats_output_dir /tmp /tmp
xdebug.gc_stats_output_name gcstats.%p gcstats.%p
xdebug.halt_level 0 0
xdebug.idekey no value no value
xdebug.max_nesting_level 256 256
xdebug.max_stack_frames -1 -1
xdebug.overload_var_dump 1 1
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 Off Off
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/apache2/xdebug.log no value
xdebug.remote_mode req req
xdebug.remote_port 9000 9000
xdebug.remote_timeout 200 200
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

This is my docker-compose.yml

version: '3.7'

services:
  php:
    build: docker-images/php
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./magento:/var/www/magento
      - ./docker-images/php/php.ini:/usr/local/etc/php/php.ini
      - ./docker-images/php/vhosts/:/etc/apache2/sites-enabled
      - ./logs/apache2:/var/log/apache2
    #links:
      #- "mysql:mysql"
    environment:
      XDEBUG_CONFIG: remote_host=host.docker.internal
      XDEBUG_CONFIG: remote_connect_back=1
      XDEBUG_CONFIG: remote_log=/var/log/apache2/xdebug.log
    networks:
      - magento
  mysql:
    image: mariadb:10.1.36
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: pw
      MYSQL_DATABASE: magento
      MYSQL_USER: shop
      MYSQL_PASSWORD: ShopPassword
    volumes:
      - ./db:/var/lib/mysql
      - ./share:/home
    networks:
      - magento

networks:
  magento:
    name: magento

What am I missing?

0
4 comments

Are you on mac? What IDE version are you running? Is the app still running inside Docker? Then you should change xdebug.remote_host to point to host.docker.internal, see https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html#configuring-xdebug-docker

1
Avatar
Permanently deleted user

Hi,
yes I am on a mac indeed. The IDE version is:

PhpStorm 2019.1.3
Build #PS-191.7479.51, built on June 18, 2019
macOS 10.14.5

Th app is running inside docker and remote_host should be set to host.internal.docker by my docker-compose.yml that I have attached above, for some reason this line doesn't seem to have any effect anymore XDEBUG_CONFIG: remote_host=host.docker.internal

I am pretty sure this was added to the config correctly before. But now when I docker-compose down and up again it doesn't change in the phpinfo anymore.
The other two settings from my docker.compose.yml still apply though. Any ideas why this is not working?

Anyways I tried this already before with different settings including the host.docker.internal and my actual IP address.
I also did a ping to my host machine from within the container to test if there's a connection and a telnet to test for port 9000. All of that worked but still the debugger didn't work.

Also, with remote_connect_back set to 1 shouldn't the remote_host setting be ignored?

0
Avatar
Permanently deleted user

Ok, so for some reason it works now.

I set remote_host to host.docker.internal and remote_connect_back to 0 and that fixed it.
This is what I found in the log before, so for some reason the connect_back doesn't seem to work correctly.

Log opened at 2019-07-03 16:04:51
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 172.25.0.1:9000.
W: Creating socket for '172.25.0.1:9000', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2019-07-03 16:04:51

Thank you very much for your assistance :)

1
Avatar
Permanently deleted user

The port for the xDebug must be open on your computer 

try this for Linux

sudo iptables -A INPUT -p tcp --dport 9000 -j ACCEPT

3

Please sign in to leave a comment.