Roots Discourse

Xdebug: Could not connect to debugging client

Hi,

I’m trying to debug an issue on a local dev site but my error.log is filled with:
Xdebug: [Step Debug] Could not connect to debugging client.

My understanding is that it should be set up out of the box, so I haven’t changed any debug settings. Any ideas?

Thanks,
James

Hey @James_Cobbett :wave:

Have you got Xdebug running?

I’m using VSCode so the below is aimed at that, if you’re using something else hopefully it gives you enough to go on.

You’ll use your site key configured in wordpress_sites.yml in Trellis

  example.com:      <-- site key
    site_hosts:
      - canonical: www.example.com

Create a folder in the site/Bedrock folder called .vscode and in there, create a file called launch.json . Paste this in:

{
  "configurations": [
    {
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/srv/www/example.com/current": "${workspaceRoot}"
      }
    },
    {
      "name": "Launch currently open script",
      "type": "php",
      "request": "launch",
      "program": "${file}",
      "cwd": "${fileDirname}",
      "port": 9003
    }
  ]
}

Change the example.com to your domain in pathMappings. This is the site key and the path should match the path on your local server.

Open your site/Bedrock folder in VSC and hit F5 to start debugging (otherwise go to the debug screen and hit the green ‘play’ button, top left) - the bar at the bottom should turn orange.

If you have multiple folders setup in a VSC workspace (for example, one for Bedrock one for Sage), you can use "${workspaceRoot:foldername}" to specify the folder to debug from. In my case, the Bedrock folder is the same as the site key, so mine is e.g. "${workspaceRoot:example.com}".

If that doesn’t help, come back and let us know how you’ve got it setup. As far as I have been able to find out, there isn’t a way to prevent the error log filling up when Xdebug isn’t running - if anyone else knows more than I do perhaps they’d be willing to share.

1 Like