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.
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.
xdebug_remote_autostart: 1 now would be xdebug_start_with_request: 1
Default "port" is now 9003, not 9000.
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.)
Just a note that Xdebug in VSCode seems to be working perfectly with the following launch.json and current Trellis 1.14.0:
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"name": "Listen for Xdebug",
I’m running PHP 8.0 in the Trellis Vagrant box and locally in macOS 12 (homebrew installation). I didn’t have to adjust the Trellis group vars at all. I’m not using the Chrome extension, so I don’t know if that’ll work.
I know I tried this quite a while ago and something wasn’t working, but I decided to give it another go. If anyone has trouble, I’d make sure your local PHP version matches what WP is using in the Vagrant box, and make sure the pathMappings are set correctly for the site you’re debugging.