Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker image bscheshir/php:7.2.5-fpm-alpine-4yii2-xdebug cannot connect to the host machine for XDebug #1

Closed
James-ZHANG opened this issue Apr 29, 2018 · 6 comments

Comments

@James-ZHANG
Copy link

James-ZHANG commented Apr 29, 2018

Hi, I've tried to set up a yii2-advanced template through your docker-compose settings. It works nicely on a first try and I could access the template application through the web browser.

However, I've had difficulty configuring the XDebug support for PhpStorm. It seems the problem is: within the container bscheshir/php:7.2.5-fpm-alpine-4yii2-xdebug you cannot connect to the host machine through a dns entry like 127.0.0.1 my-fancy-servername in /etc/hosts.

To trigger the problem:

  1. Do every step in the install.md, with the php-code directory filled with a yii2-advanced template project.
  2. Configure a php server in PhpStorm, setting port to 8080, choosing XDebug as the debugger.
  3. Debug the application in PhpStorm using a PHP Web Page debug setting.

The symptom: The application can be started in the browser, but the breakpoint cannot be hit.

@bscheshirwork
Copy link
Owner

bscheshirwork commented Apr 29, 2018

@James-ZHANG please, check next steps:
First: set remote_host

XDEBUG_CONFIG: "remote_host=dev-Aspire-V3-772 remote_port=9001 var_display_max_data=1024 var_display_max_depth=5"

to your machine IP / external DN (for example dev-Aspire-V3-772). In mac OS you can use docker special name host.docker.internal.
Second: in your PHPStorm Settings > Languages & Frameworks > PHP > Servers page set server name value is equal to serverName
PHP_IDE_CONFIG: "serverName=yii2advanced"

(other values ip, port is even don't matter).
Additional you mast set "use path mapping": /your/machine/path/to/php-code=/var/www/html.
Also in page Settings > Languages & Frameworks > PHP > Debug check correct port in Xdebug > Debug port
XDEBUG_CONFIG: "remote_host=dev-Aspire-V3-772 remote_port=9001 var_display_max_data=1024 var_display_max_depth=5"

remote_port=9001

UPD: first try with IP address in remote_host=.

@James-ZHANG
Copy link
Author

@bscheshirwork , thanks for the response. I adjusted the remote_host field of XDEBUG_CONFIG to the ip address of the eth0 gateway inside the container and it worked. In my case the value is 172.20.0.1.

However, the dns approach still does not work; and since I use ubuntu, the special name host.docker.internal approach does not apply as well. Maybe a portable way to solve this issue is per this link: https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach. To be precise, somehow set the remote_host to an environment variable set by:

export DOCKER_HOST_IP=$(route -n | awk '/UG[ \t]/{print $2}')

inside the container?

I'm pretty new to Docker and according to my understanding this cannot be done inside a Dockerfile since at the build time the container has not been attached to a virtual network yet. Any way to achieve that through docker-compose?

Last, thank you for sharing this docker compose template.

@bscheshirwork
Copy link
Owner

yes, your right. I already propose add host.docker.internal on linux.

export DOCKER_HOST_IP=$(route -n | awk '/UG[ \t]/{print $2}')

this is change container, right? I already see it solution and I against about it. Yes, you right. This is unresolved problem now.

also my example

For xdebug we can use environment (for example your developer machine is have dns record like
cat /etc/hosts
127.0.1.1 dev-Aspire-V3-772

is incorrect (this is local dns-server rule. cat /etc/hosts is wrong way). However you can use external dns-server (like you router) and use automated-signed dns, like name on your machine.
The docker use this dns-server and resolved address correctly.

Also you can use external (out of container) IP, (within case if your router set it too)

@James-ZHANG
Copy link
Author

I see, so I think it's better to update the INSTALL.md instructions accordingly. And thanks for your reply.

@bscheshirwork
Copy link
Owner

resolved in 9b9f483

@bscheshirwork
Copy link
Owner

docker/for-linux#264 (comment) @James-ZHANG you can try it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants