LocalByFlywheel + XDebug + VSCode

This is not working. It adds a launch.json to the public folder but the debug does not work. I added a breakpoint in the WordPress index file at this code require __DIR__ . '/wp-blog-header.php'; . A die statement before this is working fine but the debug is not detecting anything at all.

Do you have the PHP Debug extension installed in VS Code?

The mistake I was making was that I opened the Local project root folder, while I should have opened the project/app/public folder. Local was putting .vscode/launch.json config file in a wrong folder.
But the it still didn’t work. Finally I solved it by adding the following lines:
xdebug.mode = debug
xdebug.start_with_request = 1
xdebug.client_port = 9000
at the end of the project/conf/php/php.ini.hbs file
I hope this helps someone.
Cheers

1 Like

I’m stumped trying to get this working. I’m on MacOS Monterey and latest versions of VS Code and Local. I’ve installed the Xdebug + VS Code addon and followed the directions for adding the run configuration to app/public.

Whenever I run the debug, I get the following access error:

Error: spawn /Applications/Local/Contents/Resources/extraResources/lightning-services/php-7.3.5+11/bin/darwin/bin/php ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /Applications/Local/Contents/Resources/extraResources/lightning-services/php-7.3.5+11/bin/darwin/bin/php',
  path: '/Applications/Local/Contents/Resources/extraResources/lightning-services/php-7.3.5+11/bin/darwin/bin/php',
  spawnargs: [
    '-dxdebug.start_with_request=yes',
    '/Volumes/Media 2TB/LocalSites/bboss/app/public/wp-content/themes/brightfuturecommons/buddypress/groups/single/home.php'
  ]
}

I’ve set all of the permissions on the project and php to 777 with no effect.

I’ve tried using a homebrew-installed php but that thinks standard WordPress functions are undefined.

Any clues on what to try next would be much appreciated.

One specific question: what should php.debug.executablePath be?

The xDebug/VSCode plugin is only set up to use PHP7.4 and lower. PHP 8 requires a change as it listens on port 9003 and not on for 9000.

Thanks, @afragen, good to know but in my case I’m using PHP7.4 and lower.

I think my problem is finding the right path to php. If I use PHP7.3, will the path be
/Applications/Local/Contents/Resources/extraResources/lightning-services/php-7.3.5+11/bin/darwin/bin/php
That doesn’t seem to work when I use that in VS Code settings for php.debug.executablePath.

If I use PHP7.4, where is the executable located?

Does anyone have XDebug and VSCode working on macOS Monterey? If you do, I’ve love to know what your settings are. Mine are as follows:

In VSCode settings -
"php.debug.executablePath": "/Applications/Local/Contents/Resources/extraResources/lightning-services/php-7.3.5+11/bin/darwin/bin/php"

In lanuch.json -

"version": "0.2.0",
"configurations": [
	{
		"name": "Listen for Xdebug (Local)",
		"type": "php",
		"request": "launch",
		"port": 9000,
		"xdebugSettings": {
			"max_children": 128,
			"max_data": 1024,
			"max_depth": 3,
			"show_hidden": 1
		}
	},
	{
		"name": "Launch currently open script",
		"type": "php",
		"request": "launch",
		"program": "${file}",
		"cwd": "${fileDirname}",
		"port": 9000,
		"xdebugSettings": {
			"max_children": 128,
			"max_data": 1024,
			"max_depth": 3,
			"show_hidden": 1
		}
	}
]

In php.ini -

xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=Off
xdebug.remote_port=“9000”
xdebug.profiler_enable=0

The site is running on PHP 7.3.5

I got this to work if the workspace root is /public, but I usually have many sites open at once so it just makes things easier to open at the site level. So I move the launch.json file into my workspace folder. I am guessing I need to update the pathMappings. There are one hundred different suggestions in this thread. I’ve tried them all, to no avail.

Is there a definitive 2022 answer as to what the path mappings should look like for that scenario?

This is not working:

Good luck. I got xdebug to work for about a day and then something broke it. Hopefully when they release a new build for PHP 8.1 things get easier.

I’ve just been able to get XDEBUG working with localwp. Perhaps my experience will be of help you too.

XDEBUG related settings in php.ini for my running instance:

[xdebug]
zend_extension = php_xdebug.dll

xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

[localbyflywheel]
xdebug.scream = 1
xdebug.show_local_vars = 1
xdebug.idekey = VSCODE

In order to have these settings in your php.ini, it is imperative that the template php.ini.hbs file is edited to suit your needs. Every time you start your instance, this file is used to generate the instance php.ini. The template php.ini.hbs file can be found here:

<YourDeploymentDirectory>\conf\php

I’ve edited the file to read like this:

{{#if xdebugEnabled}}
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
{{else}}
xdebug.remote_autostart=0  
xdebug.remote_enable=0
xdebug.profiler_enable=0
{{/if}}

[localbyflywheel]
xdebug.scream = 1
xdebug.show_local_vars = 1
xdebug.idekey = VSCODE

IMPORTANT: After you edit the php.ini.hbs file, you have to restart your instance in order for your changes to take effect.

In VSCODE, the setup is quite basic. I’ve used the plugin provided by localwp to generate launch configurations. It’s important to understand what they’ve done because it’s not obvious unless you’re very well aware of XDEBUG developments. Basically, if you use the plugin, 3 launch profiles are created:

  • Listen for Xdebug 3.0 (Local) (public): This is for XDEBUG 3.x for which NO compatible version for php 7 exists.
  • Listen for Xdebug (Local) (public): This is for XDEBUG 2.x which is compatible with PHP version 7.4.3 currently available with Local.
  • Launch currently open script

So, in order to get XDEBUG to work with the PHP configuration for your instance, you will need to choose “Listen for Xdebug (Local) (public)” to have your IDE listen on port 9000 for connections of XDEBUG.

The launch configurations look like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug 3.0 (Local)",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "xdebugSettings": {
                "max_children": 128,
                "max_data": 1024,
                "max_depth": 3,
                "show_hidden": 1
            }
        },
        {
            "name": "Listen for Xdebug (Local)",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "xdebugSettings": {
                "max_children": 128,
                "max_data": 1024,
                "max_depth": 3,
                "show_hidden": 1
            }
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000,
            "xdebugSettings": {
                "max_children": 128,
                "max_data": 1024,
                "max_depth": 3,
                "show_hidden": 1
            }
        }
    ]
}

I hope this helps you (and others) to get this working.