9

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".

7
  • Which extension are you using for debugging? Maybe that extension does not support the run action as mentioned here. Commented Mar 17, 2018 at 11:59
  • @HaaLeo I only installed the PHP extension that Visual Studio Code suggested I install when I started a PHP project. Commented Mar 19, 2018 at 4:51
  • @HaaLeo So do I need to install a PHP extension to support it? It's weird that they have that menu option there and when I click it, it opens the User Settings page. I don't get why it does that. Seems like a bug. Commented Mar 19, 2018 at 4:53
  • So I guess you installed this one? Have you followed the installation guide and set up a launch.json file? Commented Mar 19, 2018 at 10:28
  • 1
    @HaaLeo Thanks for your help. I found out that I don't need to install xdebug or the PHP extension. I found this section in the vscode doc and this comment that mentions creating a global launch configuration. I just had to put this launch object in my User Settings with runtimeExecutable pointing to my PHP executable. After I did that, it executed the PHP file when I pressed Ctrl+F5 and displayed the output in the debug panel. Commented Mar 21, 2018 at 2:44

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I just realized this solution was already posted here: stackoverflow.com/questions/36868021/…. Hopefully my answer helps someone who needs the PHP configuration.
I ran into this same issue trying to run a C++ file. It's mind blowing to me that this is the expected solution.
1

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).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.