Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio Code show User Settings instead of running a PHP file?

I noticed that in Visual Studio Code there is a menu item called "Start Without Debugging" under the "Debug" menu. When I have a PHP file open, I expected this to run the PHP file through the PHP executable and give me the output. Instead, when I click on "Start Without Debugging", the User Settings page shows up. Why does the User Settings page show up? It's not clear why this page is presented to me. Does it want me to configure something? How do I get it to just run the PHP file that I have open through the PHP executable. Is this even possible?

I noticed in the Default Settings there is a property called "php.validate.executablePath" that is set to null. I tried overriding this setting in my User Settings by pointing it to the path of my PHP executable like this:

{
    "php.validate.executablePath": "/usr/bin/php"
}

But that didn't solve anything. The User Settings page still shows up when I click "Start Without Debugging".

like image 747
Cave Johnson Avatar asked Mar 15 '18 02:03

Cave Johnson


People also ask

Why php is not working in VS Code?

Go to File->Preferences->settings->User settings tab->extensions->from the drop down select php->on the right pane under PHP › Validate: Executable Path select edit in settings.

How do I display php output code in Visual Studio?

You can search for PHP extensions from within VS Code in the Extensions view (Ctrl+Shift+X) then filter the extensions dropdown list by typing 'php'.

Do workspace settings override user settings VS Code?

Workspace settings are specific to a project and can be shared across developers on a project. Workspace settings override user settings. Note: A VS Code "workspace" is usually just your project root folder.


2 Answers

After doing more research, I found the solution to my problem. Based on this section in the vscode docs and this comment that mentions creating a global launch configuration, all you have to do is add a launch object to your User Settings JSON.

In my case, I added this to my User Settings:

"launch": {
    "version": "0.2.0",
    "configurations": [
        {
        "type": "php",
        "request": "launch",
        "name": "Launch Program",
        "program": "${file}",
        "runtimeExecutable": "/usr/bin/php"
        }
    ]
}

Your value for runtimeExecutable may be different depending on the path to your PHP executable.

like image 118
Cave Johnson Avatar answered Oct 18 '22 04:10

Cave Johnson


I ran in to the same issue except I was trying to run a C++ file (doing all this in Windows 11). I followed the instructions here, which said that I needed to run VSCode from within a "developer terminal" (which is able to run cl, the command for the MSVC C++ compiler).

At first, I did so and it still did not work (I'm absolutely sure of this). But then I tried again and it worked; I was able to run and debug a hello.cpp. Not exactly sure what happened, maybe it needed time to "warm up" or something (which would be awful if true).

like image 1
xdavidliu Avatar answered Oct 18 '22 02:10

xdavidliu