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

Connection with 'xdebug 2.4.1' was not established. #460

Closed
0xuhe opened this issue Nov 30, 2016 · 17 comments
Closed

Connection with 'xdebug 2.4.1' was not established. #460

0xuhe opened this issue Nov 30, 2016 · 17 comments

Comments

@0xuhe
Copy link
Contributor

0xuhe commented Nov 30, 2016

I followed the guide of xdebug for phpstorm step by step.
But got the following issue.
Connection with 'xdebug 2.4.1' was not established

I'm not sure if I have configured correctly.
In the host, I add some host in etc/hosts

127.0.0.1       laravel
172.18.0.1      dockerhost

In the docker-compose.yml

### workspace contaner

extra_hosts:
            # IMPORTANT: Replace with your Docker Host IP (will be appended to /etc/hosts)
            - "dockerhost:172.18.0.1"


### php-fpm container

 extra_hosts:
            # IMPORTANT: Replace with your Docker Host IP (will be appended to /etc/hosts)
            - "dockerhost:172.18.0.1"
        environment:
            # IMPORTANT: Set the Remote Interpreter entry matching name to `laravel`
            - PHP_IDE_CONFIG=serverName=laravel

image

I have configured the ssh, so I could ssh with the command ssh -p2222 root@laravel, and success visit http://laravel/ in host browser.

phpunit worked fine, but failed when debug.

sftp://root@laravel:2222/usr/bin/php \ 
  -dzend_extension=/usr/lib/php/20151012/xdebug.so\
  -dxdebug.remote_enable=1 \
  -dxdebug.remote_mode=req \
  -dxdebug.remote_port=9000 \
  -dxdebug.remote_host=172.18.0.1 
  /var/www/laravel53/vendor/phpunit/phpunit/phpunit \
  --configuration /var/www/laravel53/phpunit.xml ExampleTest \ 
  /var/www/laravel53/tests/ExampleTest.php --teamcity

image

I noticed that it is php7.0.9 in php-fpm container, but we actually using the php7.0.12 cli in workspace.

@LarryEitel
Copy link
Contributor

What is the exact error message?

@0xuhe
Copy link
Contributor Author

0xuhe commented Dec 1, 2016

Connection with 'xdebug 2.4.1' was not established when debuging in phpstorm

@0xuhe
Copy link
Contributor Author

0xuhe commented Dec 1, 2016

I noticed that xdebug.remote_host=dockerhost in php-fpm container and workspace container, I modify in extra_hosts part dockerhost:172.18.0.1. This ip is my host ip

@LarryEitel
Copy link
Contributor

Here is 'a' way to find the correct IP for laravel that you would place in your hosts file:

@0xuhe
Copy link
Contributor Author

0xuhe commented Dec 2, 2016

I am using MacOS, I find my host ip in nginx logs, that is 172.18.0.1

@LarryEitel
Copy link
Contributor

I run on Windows 10. I wonder if anyone using MacOS can respond to this.

@LarryEitel
Copy link
Contributor

I am aware of at least one other MacOS user that was unable to connect to local IP from Docker Contain. Never heard anything further.

@0xuhe
Copy link
Contributor Author

0xuhe commented Dec 2, 2016

I find that the PHPSTORM always get the php information as xdebug.remote_enable 0.
I have tried uncomment the line zend_extension=xdebug.so in /etc/php/7.0/cli/conf.d/20-xdebug.ini, so I saw the xdebug.remote_enable on=>on in workspace container. but PHPSTORM seems still get the php information as xdebug.remote_enable 0.

@aledelgo
Copy link

aledelgo commented Dec 5, 2016

Hello,
found the real problem inspecting forced xdebug logs...
I'm on windows 10 and i'm gettnig the same problem connecting to xdebug for both UnitTest and remote debugging.

The problem is that, on NGINX side, requests seems to come from the gateway of docker instead from the dockerhost ip.

See this nginx access.log line:
172.20.0.1 - - [05/Dec/2016:10:36:07 +0000] "GET / HTTP/1.1" 404 162 "-" "-"

the IP is 172.20.0.1 but my dockerhost ip (the one on the Docker network i have on windows) is 10.0.75.2

this is the xdebug log:

Log opened at 2016-12-05 14:42:22
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.20.0.1:9000.
W: Creating socket for '172.20.0.1:9000', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2016-12-05 14:42:22

also, while checking port 9000 on 10.0.75.2 (my docker host) from the php-fpm container give an OK (i mean php-fpm can reach that port on that ip), the same check on 172.20.0.1:9000 give a KO:

timeout 1 bash -c 'cat < /dev/null > /dev/tcp/172.20.0.1/9000'
bash: connect: Connection refused

This is the inspection of php-fpm container:

                    "Gateway": "172.20.0.1",
                    "IPAddress": "172.20.0.2",

Now i'm missing how to solve this problem as apparently Nginx is not used as reverse proxy so i would avoid remote-address replacing.

Do you know of any solution?

PS. a solution that worked for me after discovering this is to set
xdebug.remote_connect_back=0
This force xdebug to use
xdebug.remote_host=dockerhost
as remote host and not the remote_address that is wrong

Anyway actually it seems phpstorm can't show me the execution point, it breaks but i don't see where the execution point is in the code. probably this is an IDE/mapping problem i have to investigate.

@aledelgo
Copy link

aledelgo commented Dec 6, 2016

Hello,
further investigating take me to this post:
dockerfile/nginx#27
that states the problem is with docker and ipv6, so i disabled IPV6 binding on NGINX but it doesn't work. remote_addr is still set with the bridge ip.

then i've read this on the docker repo:
moby/moby#15086

it seems is a known problem.

@mikeerickson
Copy link
Contributor

Has anybody gotten this to work on macOS? I have been fighting this for past two hours and getting nowhere :-(

@lechengyu
Copy link

I am running laradock on windows10 with docker 1.12.5(9503), and the host ip in docker is 172.18.0.1.

These settings works for me:

  • for laradock configurations, set xdebug.remote_connect_back = 0

  • in phpStorm debug configurations, set the interpreter options

    qq 20170213085900

@HolyKindom
Copy link

HolyKindom commented Feb 22, 2017

@lechengyu it works! You solve the problem I have met for a long time.
Specify the interpreter options in Command Line (:"-dxdebug.remote_host=10.0.75.1") can solve the problem which is met in phpstorm.
PS:"10.0.75.1" is the host ip for docker(Hyper-v) in Windows.On mac ,maybe we can use a loopback ip ****.
Whatever,before debugging the testcase,we can "telnet **** 9000" to test if the xdebug in the docker can connect the host and port. And **** is the truely remote_host ip.
( Remember : click the 'telephone icon' in the tool-menu of the phpstorm at the top left corner !)

@appleboy
Copy link
Member

@lechengyu Could you send the PR to improve document?

@NewbMiao
Copy link

NewbMiao commented Mar 10, 2017

@HolyKindom
For mac, the ip you mean is what ifconfig en0 show? right?
For my mache it is inet 172.16.30.192 netmask 0xffffff00 broadcast 172.16.30.255
so i changed dockhost

 extra_hosts:
            # IMPORTANT: Replace with your Docker Host IP (will be appended to /etc/hosts)
            - "dockerhost:172.16.30.192"

Now i can debug with php-fpm.
But I still dont know am i do this right, cause my host ip will be changed when i changed wifi!

Updated:
I found a way to make host ip never changed:
set host ip never changed

@ricardosaracino
Copy link

ricardosaracino commented Jul 28, 2018

I just spent to long on this issue I had remote_connect_back set to 1 incorrectly. Thanks to @lechengyu

this is the config that works
; Enable xdebug extension module
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_connect_back=0
xdebug.remote_port=9001
xdebug.profiler_enable=0
xdebug.profiler_output_dir="/var/www/html"
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=192.168.0.11
xdebug.idekey="IDEA_DEBUG"
xdebug.remote_autostart=1
xdebug.remote_log=xdebug_remote.log

@felly
Copy link

felly commented Sep 25, 2019

In my case I've added the following Interpreter options at the PHPUnit Run Configuration:
-dxdebug.remote_host=host.docker.internal

Screenshot

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

No branches or pull requests