craftcms / nitro

Speedy local dev environment for @craftcms.
https://getnitro.sh
MIT License
178 stars 24 forks source link

Xdebug and Linux: host.docker.internal #288

Closed sidneywidmer closed 3 years ago

sidneywidmer commented 3 years ago

Description

Currently xdebug does not work on linux since xdebug.client_host is hardcoded to host.docker.internal which does not exist in docker for linux.

Since docker version 20.10 it's possible to add it manually: https://github.com/docker/for-linux/issues/264#issuecomment-714253414 so this could potentially be a simple fix.

I also tried to overwrite it in a custom .user.ini which didn't work (maybe the ENV var gets priority?).

Steps to reproduce

  1. nitro ssh
  2. ./craft --> Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(

Additional info

It would be nice if there was a simple way to set custom env vars, preferably in the nitro.yaml but i think this is a different issue :)

jasonmccallister commented 3 years ago

@sidneywidmer I see where this is an issue and will get resolved with the next release! Sorry about that.

The Xdebug documentation can be a little hard to read but the environment variable takes precedence.

jasonmccallister commented 3 years ago

@sidneywidmer looking into this, does the host host-gateway resolve while inside a container using nitro ssh --root (ping is not available as the www-data user)?

sidneywidmer commented 3 years ago

No, this is just a special string that gets resolved to the hosts IP if used in the --add-host parameter. Just to double check i tried to ping it (as root) and as expected I get ping: bad address 'host-gateway'. Together with said add-host param it can be used to make host.docker.internal as domain name available inside docker containers on linux.

sidneywidmer commented 3 years ago

Thanks for fixing the issue - I just tested it out and I could successfully debug with phpstorm :+1:

Keep up the good work, I really like the direction this project is going :rocket: