Roots Discourse

Xdebug in VS Code – working for anyone?

Anyone successfully using Xdebug in Microsoft VS Code (on a Mac)?

I’ve got the PHP Debug VS Code extension (by Felix Becker) installed and I have the Xdebug Helper extension running in Chrome (with correct IDE Key in place).

I set a breakpoint in a template file, run Listen for XDebug but nothing returned at all.

However, if I run with the setting "stopOnEntry": true, then I can see a connection is being made (some variables returned), although it stops with an error:

Unable to open 'index.php': File not found (/srv/www/

Any ideas or does anyone have things configured correctly?

For whatever reason, I seem to get further using Sage 9. However, I get the error:

Unable to open 'Container.php': File not found (/srv/www/

When I SSH into the Vagrant box, I can confirm this fie definitely does exist.

The connection is being made, as some variables make it through but it exits when it hits that error.


Try updating your launch.json file and setting “serverSourceRoot” and “localSourceRoot”. Example (the localSourceRoot points to the folder on my Mac):

        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "localSourceRoot": "/Users/userfolder/apps/webapp",
        "serverSourceRoot": "/var/www/webapp"

I was setting up PHP Debug for the first time this morning and I was getting the same kind of error messages prior to making this change in my launch.json. Hope it helps in your case too. You might also be able to get additional information by setting up XDebug logging.

Thanks for this. Got a step closer with the config as:

    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "port": 9000,
    "localSourceRoot": "/Users/nat/roots/",
    "serverSourceRoot": "/srv/www/"

However, now I get:

Exception has occurred.
Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Container\Container] is not instantiable while building [Illuminate\Events\Dispatcher].

Thrown in container.php. Hummm…

Also, doesn’t look like you can set up breakpoints in .blade.php files, only straight .php files…

Anything new on this? We are considering switching to Trellis as our foundation of WordPress sites. But we are not able to get Xdebug to work at all.

It’s working great for me with the Chrome XDebug Helper extension, VS Code XDebug extension and the following in my launch.json

            "name": "PHP: Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/srv/www/": "${workspaceFolder}/site/web"

Select “debug” on the current tab in chrome from the extension dropdown then press “play” on “PHP: Listen for XDebug” in VS Code, run the page and voila!

It also helps for debugging if you throw in an xdebug_break(); where you want the script to pause!

EDIT: using Sage 8.5.x so YMMV on Sage 9?
EDIT: localSourceRoot and serverSourceRoot should point to [...]/web not [...]/web/app, otherwise VS Code will show a “File not found” error when trying to open files in the [...]/web/wp directory (WP Core files).
EDIT: looks like localSourceRoot and serverSourceRoot are both now deprecated in favor of pathMappings, updated code snippet to reflect this change.

1 Like

I am using CodeLobster IDE with xDebug on Mac.

Anyone coming to this thread might be interested in @nathanielks series:


In the debug window, you can untick “Everything” under “Breakpoints” and it should continue and break at your breakpoints.

This helped me solve a problem with configuring xdebug for VS Code and get back to developing my application. Worth the money! I’m no longer frustrated :slight_smile: Thanks @nathanielks


You are so welcome! I’m glad it was able to help you :smiley:

How to fix the error “Cannot evaluate code without a connection"?

xdebug.mode = debug,develop,trace
xdebug.start_with_request = yes


“version”: “0.2.0”,
“configurations”: [
“name”: “Listen for XDebug”,
“type”: “php”,
“request”: “launch”,
“port”: 9003
“name”: “Launch currently open script”,
“type”: “php”,
“request”: “launch”,
“program”: “${file}”,
“cwd”: “${fileDirname}”,
“port”: 9003

php7.2 xdebug3.0.4 vscode1.51 Linux

I’m struggling a bit with this, too. Purchased @nathanielks’s wonderful tutorial (, and working with with Visual Studio Code (v1.59.1), php 7.4.22 and xDebug v3.0.4.

Check the xDebug upgrade guide.

A few updates to the tutorial for xDebug 3:

  1. Make sure you are using current defaults for the role and check the template and tasks.
  2. xdebug_remote_autostart: 1 now would be xdebug_start_with_request: 1
  3. Default "port" is now 9003, not 9000.
  4. roles/xdebug/defaults/main.yml is a good starting place for vars to override in group_vars/development/php.yml, for example xdebug_show_local_vars defaults to 0.

You may want to rebase your updates over the latest trellis. Make sure you are working with a .git base directory of trellis and not the directory above site and trellis. Also make sure group_vars/all/main.yml contains php_version: "7.4", which is a new parameter.

Provisioning just xDebug:

ANSIBLE_TAGS=xdebug vagrant provision

(For some reason reprovisioning via trellis-cli fails, at least called with $ trellis provision --tags xdebug development yields /bin/sh: lsb_release: command not found.)