Smiffy's avatar

Laravel 9 with Sail: XDebug not connecting

First time using Sail for development and all went smoothly. However I am now looking to get XDebug working but this is causing me issues. My Sail output reports:

laravel.test_1  | [Tue May 31 09:31:20 2022] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(

According to the docs for Sail, my setup should be quite minimal, The only entry I have added to .env is: SAIL_XDEBUG_MODE=develop,debug. The docs state that I should be fine not specifying SAIL_XDEBUG_CONFIG as my system is using the minimum requirements to use host.docker.internal:

$: docker -v
Docker version 20.10.14, build a224086

$: docker-compose -v
docker-compose version 1.27.4, build unknown

Even if SAIL_XDEBUG_CONFIG="client_host=host.docker.internal" is added, this still results in the same behaviour.

My IDE is VSCode. For completeness, this is my config for the debugger in launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Sail Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html": "${workspaceFolder}"
            },
            "hostname": "localhost",
            "ignore": ["**/vendor/**/*.php"],
            "xdebugSettings": {
                "max_data": 65536,
                "show_hidden": 1,
                "max_children": 100,
                "max_depth": 3
            }
        },
    ]
}

Any suggestions?

0 likes
7 replies
Smiffy's avatar

@folium I have added SAIL_XDEBUG_CONFIG="client_host=host.docker.internal" to my .env (which I don't believe is needed.) this still results in the same issue. Was there something specific in that SO post that you wanted to draw my attention to?

Smiffy's avatar
Smiffy
OP
Best Answer
Level 4

Took me a while to find this but it was a firewall issue. I had to open up port 9003 to allow traffic from the container to the host. Hopefully this helps someone as it threw me for a while...!

1 like
Smiffy's avatar

@exSnake No. It was my internal firewall. I use Ubuntu so used ufw to amend.

pasilyo's avatar

@Smiffy Thank you, i've figures to add the '9003:9003' on ports on docker-compose.yml.

I posted my answer here: stackoverflow.com/a/73809254/1500392

1 like
gianmarx's avatar

@pasilyo this of all is the only one that has removed the error Xdebug on port 127.0.0.1:9003 ... [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port). but now the launch.json fails me and I don't understand why it is the following :

{ "version": "0.2.0", "configurations": [ { "name": "Listen for Xdebug", "type": "php", "request": "launch", "port": 9003, "pathMappings": { "/var/www/html": "${workspaceFolder}" }, "hostname": "localhost" }, ] }

Please or to participate in this conversation.