Xdebug + VS Code does not work with Local

Bug Summary

Xdebug + VS Code does not work. You cannot connect to a Local WordPress site using the plugin and step through the code using the instructions given.

Summarize the issue in one to two sentences.
Xdebug + VS Code does not work.

Steps to reproduce

I made a video of the installation of Local and VS Code so that you can see the exact steps that I took and how it fails. This is not a great video as I had already been trying to figure this out for over 12 hours on my own and I am coming down with a cold or something, but it illustrates the problem just the same.

As precisely as you can, list the steps it takes to reliably reproduce the issue.

Environment Info

Describe your environment.

  • What Operating System are you using?
    Windows 10 Pro
    Version 22H2
    OS build 19045.3570
    Experience Windows Feature Experience Pack 1000.19052.1000.0

  • What versions of site software (Nginx, Apache, PHP, MySQL) is used?
    nginx doesn’t state a version on the site’s dashboard
    PHP 8.1.23
    MySQL 8.0.16
    WordPress 6.3.1

  • What version of Local is installed?
    Version 8.0.0+6475

Supporting info

Please provide your Local Log. See this Community Forum post for instructions on how to do so:
local-lightning.log (4.2 KB)
local-lightning-verbose.log (48.4 KB)

Include any screenshots or video recordings of the issue to help others reproduce.
Here ya go - 28 minutes of frustration – https://youtu.be/j3-DJmXGKJ4

What issue or error are you experiencing?

i7 snagit 10-12-2023 9.33.38 AM

Cannot validate since a PHP installation could not be found. Use the setting ‘php.validate.executablePath’ to configure the PHP executable.


What steps can be taken to replicate the issue? Feel free to include screenshots, videos, etc

Install Local.
Install a default WordPress site.
Install the Xdebug + VS Code extension for that site.
Restart Local.
Click the “Add Run Configuration to VS Code link”.
Open VS Code and open the directory (D:\Local Sites\wptest for me).

Then I saw the error “Cannot validate since d:\Local Sites\wptest\ is not a valid php executable. Use the setting ‘php.validate.executablePath’ to configure the PHP executable.” at lower right in VS Code.


System Details

I don’t know what you are asking for here…

  • Local Version:
    Version 7.2.1+6433

  • Operating System (OS) and OS version:
    Windows 10 Pro
    Version 22H2
    OS build 19045.3570
    Experience Windows Feature Experience Pack 1000.19052.1000.0


Local Logs

Attach your Local Logs here (Help Doc - Retrieving Local’s Log)


Security Reminder
Local does a pretty good job of scrubbing private info from the logs and the errors it produces, however there’s always the possibility that something private can come through. Because these are public forums, always review the screenshots you are sharing to make sure there isn’t private info like passwords being displayed.

Hi @jim_hubbard

Another user was running into similar issues recently. You might find some helpful troubleshooting steps in this thread:

Another helpful thread here as well:

Thanks for the links…

As far as the first one is concerned…I have Local installed in C:\local and I have my sites (to speed things up hopefully) on my D drive at “D:\Local Sites” so my test site location for the index.php file of the WordPress installation is in the folder “D:\Local Sites\wptest\app\public”.

When I try and edit the json.settings file and add the path to php.exe, SOMETHING is adding the path to the app to the beginning of the path to php.exe…

To be sure that nothing on my Windows 10 Pro PC could be causing these issues, I created a clean Windows 10 Pro virtual Machine in VMware and installed Local and VS Code to see if things would work there.

They did not. Be forewarned that I am exhausted in the video (I care for a parent with Parkinson’s full time and I had been working on this issue for 12 hours). I won’t win any Oscars, but I hope it shows the entire process of trying to get Local and the Xdebug + VS Code plugin to work. It’s damned frustrating.

Here ya go - https://youtu.be/j3-DJmXGKJ4

What issue or error are you experiencing?

When clicking “Go Live” in VS Code to see the site while running (and hopefully one day debugging) the site in Local, all the browser shows is the directory of the WP site - not a running site.


What steps can be taken to replicate the issue? Feel free to include screenshots, videos, etc

Install Local.
Install a default WordPress site.
Install the Xdebug + VS Code extension for that site.
Restart Local.
Click the “Add Run Configuration to VS Code link”.
Open VS Code and open the directory (D:\Local Sites\wptest\app\public for me).

Click on “Go Live” in VS Code
i7 snagit 10-12-2023 9.48.32 AM

Then you see a directory instead of the WP app


System Details

  • Local Version:
    Version 7.2.1+6433

  • Operating System (OS) and OS version:
    Windows 10 Pro
    Version 22H2
    OS build 19045.3570
    Experience Windows Feature Experience Pack 1000.19052.1000.0


Local Logs

Attach your Local Logs here (Help Doc - Retrieving Local’s Log)
local-logs1.zip (67.0 KB)


Security Reminder
Local does a pretty good job of scrubbing private info from the logs and the errors it produces, however there’s always the possibility that something private can come through. Because these are public forums, always review the screenshots you are sharing to make sure there isn’t private info like passwords being displayed.

Hi @jim_hubbard!

Thank you for all of your detail on this topic. I’ve gone ahead and merged your posts from today into one single spot in order to keep everything together. I’ve also shared everything you’ve sent over with our Local Devs for some insight and potential assistance here. Thank you for your patience with us as we take a deeper look!

1 Like

I found part of the problem - at least the “Cannot validate…” PHP issue.

i7 snagit 10-12-2023 2.25.52 PM

Being new to VS Code and web development I made a couple of rookie mistakes. The first was not knowing that the settings in settings.json must be within brackets. In other videos that I had seen, it appeared that the person talking about php.validate.executablePath did not have their variables within the brackets and I only found this error through continuous trial and error.

In fact, if you look at Microsoft’s own documentation about VS Code settings at Visual Studio Code User and Workspace Settings , you will find nothing that states the most basic thing about editing the settings.json file - that all settings should be inside brackets. I just assumed it was like a php.ini file and each line would hold a different setting.

Also, although I am still not clear on why, when adding a path to the settings.json file for php.validate.executablePath you must convert every backslash into double-backslashes. I don’t know why this is the case, but if you enter something like

“php.validate.executablePath”: “C:\Users\kitte\AppData\Local\Programs\Local\resources\extraResources\lightning-services\php-8.1.23+0\bin\win64\php.exe”

it will fail, whereas

“php.validate.executablePath”: “C:\Users\kitte\AppData\Local\Programs\Local\resources\extraResources\lightning-services\php-8.1.23+0\bin\win64\php.exe”

will succeed.

The double backslashes are not showing above because this editor corrects them for some odd reason (yet another thing that makes no logical sense). This is what the forum editor shows…

The final entry that worked looks like this…

So I am not getting the PHP “Cannot validate” error at this point.

Now I need to see what I am doing wrong about breakpoints. So far my first attempts at setting a break point and having the execution of the code stop on that breakpoint have failed. I am sure that it will be like the PHP error where the most basic thing has been glossed over by more experienced developers and I am just missing it.

Hi @jim_hubbard

One of our Devs tested getting this working on a Windows machine with Local 7.2.1 and VSCode. They were able to get it working just by following the steps on the Xdebug Add-On page. The warning did pop up regarding not being able to validate due to an invalid PHP executable, but that’s able to be closed out and ignored.

Here are the steps taken for the initial install:

  1. Install Local
  2. Install the XDebug VSCode plugin
  3. Create a new preferred site
  4. Click the Add Run Configuration to VS Code button under the Tools tab
  5. Enable XDebug on the site in question
  6. Open VSCode
  7. Install the PHP Debug extension
  8. Add the site’s /app/public directory to the VSCode workspace
  9. Verify the launch.json config exists within your site’s .vscode folder (from step #4)
  10. Add a breakpoint (I put mine in the wp-config.php file where the DB_NAME is defined)
  11. Navigate to the VSCode debug tab and start listening for XDebug using the newly created config
  12. Start your site in Local and verify VSCode catches at your breakpoint

Let us know if that helps or what other questions or issues you might have here!

2 Likes

BEAUTIFUL! I’m stopped at define( ‘DB_NAME’, ‘root’);.

I ran into a couple more issues - one of which was a mu-plugin that I just had to manually remove from the backups before importing into the WP instance in local.

I need to do these steps a dozen or so times to drill it into my thick skull. After that I’ll make a little video so that others can find it on YouTube and hopefully get it running on the first try.

Thanks so much for your help! I’ll sleep like a baby tonight…

1 Like

Thank you so much for all of your patience and communication with us @jim_hubbard! Happy Developing :green_heart: If you need anything else you know where to find us :sunglasses:

1 Like

Hello, what is the " 1. Install the XDebug VSCode plugin"? When I open the VSCode Extensions list and search on ‘xdebug’ I see only “PHP XDebug” v0.0.7 ( VS Code PHP Xdebug)… is this the one? TIA

P.S. The Add-ons Library - Local page seems to be a redirect? I see nothing here specific to XDebug or VSCode.

Hi @g_dub

Sorry, that page goes to our documentation around building an add on, but our help docs area has more information about our specific add ons such as our XDebug + VSCode one:

Excellent thx!! BTW that page (Xdebug within Local - Local) is the one that has the confusing link

Altho that first link no longer goes to the generic Local support doc but one specific for xdebug… thanks!

Sorry for that confusion @g_dub - I believe the intention there is if you wanted to learn more in order to assist with the development of this add on or a new add on since our add ons are open concept.

Thanks for giving solution in details. My vs code is working correctly.

1 Like

Glad to hear it @maltasa! Thank you for sharing.