0

I'm using PhpStorm on Mac. I'm trying to debug a Laravel application inside the Sail container on the remote Ubuntu server.

Error that I can see from Xdebug inside Sail container is:

[17] Log opened at 2021-09-26 21:24:59.590599
[17] [Step Debug] INFO: Checking remote connect back address.
[17] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[17] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 89.164.145.129:9003.
[17] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9003. :-|
[17] [Step Debug] INFO: Connected to debugging client: XXX.XXX.XXX.XXX:9003 (from HTTP_X_FORWARDED_FOR HTTP header), host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port). :-)
[17] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/server.php" language="PHP" xdebug:language_version="8.0.5" protocol_version="1.0" appid="17" idekey="phpstorm"><engine version="3.0.4"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2021 by Derick Rethans]]></copyright></init>

[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

[17] [Step Debug] WARN: 2021-09-26 21:24:59.896494: There was a problem sending 179 bytes on socket 10: Broken pipe.
[17] Log closed at 2021-09-26 21:24:59.898408

I've set up server, SSH tunnel, auto file deployment, Xdebug, and validated in PhpStorm, but I keep getting this error.

The issue is that PhpStorm is listening for debug connections, but retrieves none, debug is not triggered in the IDE.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Mario
  • 151
  • 4
  • 16
  • Does `file:///var/www/html/server.php` refer to a local file or a file in the container? – apokryfos Sep 26 '21 at 22:06
  • According to [this question](https://stackoverflow.com/questions/55844560/remote-debugging-via-ssh-tunnel-receiving-there-was-a-problem-sending-x-bytes), this can be caused by a port conflict. Are you using the same port for debugging as HTTP? – Nick ODell Sep 26 '21 at 22:20
  • 1
    There are no PhpStorm commands in the log, so it's not PhpStorm that Xdebug is connecting to. 1. You need to disable `xdebug.discover_client_host`, it's not going to work in your setup. 2. `host.docker.internal` normally doesn't work on Linux. You either should apply [the workaround](https://github.com/docker/for-linux/issues/264#issuecomment-759737542) or use the Linux server's IP address (ens0/eth0/whatever) instead – Eugene Morozov Sep 26 '21 at 23:40
  • @EugeneMorozov On some distros it now seems to work straight away without any extra tricks (diff Docker build?) – LazyOne Sep 27 '21 at 08:35
  • 1
    @Mario There are no PhpStorm response in the log. That has to be some another service. Could be php-fpm or any other that is aware of Xdebug protocol (php-fpm actually replies with such short "go away, nothing to debug here" responses). Double check with `netstat` or alike tool (`sudo lsof -nP -iTCP -sTCP:LISTEN` on Mac) what app is actually listening on that TCP 9003 port. It has to be PhpStorm. if it's not -- sort it out. – LazyOne Sep 27 '21 at 08:39
  • @LazyOne Only one listening to that port is phpstorm. – Mario Dec 02 '21 at 18:22

3 Answers3

9

I had the same issue and this is how I fixed it. I use Idea Intellij, but I guess it is no different. On Mac:

In Idea Intellij > Pereferences > Lagnuages & Frameworks > PHP > Debug > Xdebug > Debug port. The value was 9000, 9003 and in my php.ini the debug port was 9003

xdebug.client_port="9003"

so I change the port to be only 9003 and it worked!

enter image description here

Adelin
  • 18,144
  • 26
  • 115
  • 175
2

Thanks a lot! Really cost me two hours. Not so helpful error messages of PHPSTORM. It worked for webbased debugging but CLI no way. Confusing that the PHPUNIT CLI session starts with only the first port noted in the preferences as a CLI config argument. That way it got to the wrong port as I still had 9000 (xdebug v2) and 9003 (v3) noted, which worked for webbased debugging...

Thus: PHPSTORM should not make it possible to listen to more ports, or denote clearly that with CLI debugging only the first port get explicitly called as an CLI argument. Which, when using nginx/php-fpm like I do, is not working while port 9000 is taken by php-fpm.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 07 '22 at 00:40
0

I was debugging PHP in one Docker container and came to a point where a subsequent request was sent to another Docker container.

The subsequent request didn't start even if XDEBUG is properly configured on the second Docker container. xdebug.log contains: [161] [Step Debug] WARN: 2022-09-02 19:59:34.526179: There was a problem sending 179 bytes on socket 7: Broken pipe.

After hours of debugging I found out, that I had to send X-Forwarded-For header:

$response = $guzzle->request(
    'POST',
    '/my-uri',
    [
        'form_params' => [
            ...
        ],
        'headers' => [
            'X-Forwarded-For' => $_SERVER['HTTP_X_FORWARDED_FOR']
        ]
    ]
);

php.ini xdebug config:

xdebug.client_host=host.docker.internal
xdebug.client_port=9000

xdebug.mode=debug
xdebug.start_with_request=1
xdebug.discover_client_host=1

I hope this will save somebody some time.

digitalstraw
  • 403
  • 3
  • 7