0

I am trying to debug a Laravel application using docker, X-debug2.7.2, centos, and php7.3.7 However, the breakpoint is not respected. The log is updated with the following message.

[41] Log opened at 2019-10-02 21:09:33
[41] I: Connecting to configured address/port: docker.for.win.localhost:9000.
[41] I: Connected to client. :-)
[41] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/public/index.php" language="PHP" xdebug:language_version="7.3.6" protocol_version="1.0" appid="41"><engine version="2.7.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright></init>
[41]
[41] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
[41]
[41] Log closed at 2019-10-02 21:09:34

XDebug Configuration

xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.remote_enable = 1
xdebug.remote_host = docker.for.win.localhost
xdebug.remote_log = "/tmp/xdebug.log"
xdebug.remote_port = 9000

Vscode Configuration

        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/var/www": "${workspaceRoot}"
              }
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000,
            "pathMappings": {
                "/var/www": "${workspaceRoot}"
            }
        }

UPDATE

After many attempts, I 've set the remote_host at x-debug configuration to the IP of my local machine and it worked.

For those who believe that the alias host.docker.internal would work, it didn't. So what I did was to set a fictional name for the remote_host key and I configure it in the docker-compose as an extra host with the local IP.

I didn't consider this a good solution, because everyone using this configuration file will need to change it locally. So I would like to know if you guys have a better solution for this case.

  • Possible duplicate of [Debug PHP with VSCode and Docker](https://stackoverflow.com/questions/52579102/debug-php-with-vscode-and-docker) – Roaim Oct 03 '19 at 03:23
  • It's not the same case. I've already tried all the steps mentioned in quoted topic before creating this one. I'm not sure the OS influence on this issue, however, the previous image I used which was directly from PHP docker hub repository worked fine, on the other hand, this using centOS doesn't. – Carlos Vinicius Oct 04 '19 at 13:33

2 Answers2

1

This likely indicates that something else is listening on port 9000. Are you using PHP-FPM? If so, please either change the PHP-FPM port to something else, or the Xdebug one. Your IDE has a setting for it ("port": 9000, twice), and in php.ini you can use xdebug.remote_port=9001 (as an example). Please do also restart your web server if you make that php.ini (or 90-xdebug.ini, or whatever it is called) change.

Derick
  • 35,169
  • 5
  • 76
  • 99
  • I've already tried this before posting this question and it didn't work. The log indicates that the connection between docker and the IDE is established, however, I don't know why the breakpoint is not highlighted in the IDE. Using your suggestion, it didn't connect to the client, and the Xdebug logged as the following. ``` [57] W: Creating socket for 'docker.for.win.localhost:9001', poll success, but error: Operation now in progress (29). [57] W: Creating socket for 'docker.for.win.localhost:9001', connect: Cannot assign requested address. [57] E: Could not connect to client. :-( ``` – Carlos Vinicius Oct 04 '19 at 12:48
0

This may be a funny question, but are you using a plugin for your browser to communicate with xdebug? Like 'debugging' (firefix) or 'Xdebug-helper' (chrome)

Tig
  • 38
  • 4