63

I'm running windows 10 fresh copy and I just installed visual studio code. I was trying to develop a PHP project using VS Code. But I'm having trouble in setting up the environment.

I saw a blog post and I downloaded the binary file of PHP 7 and place it in the "C" drive. Then I set path variable too.

But still, I'm getting this issue.

enter image description here

1
  • 1
    Add your folder where your php.exe is to your Windows PATH variable. I edited 'user configuratio' in VS Code but it didn't help. After that I added php folder to my PATH variable and now it works. Commented Dec 5, 2018 at 20:49

14 Answers 14

99

You installed PHP IntelliSense extension, and this error because of it.
So if you want to fix this problem go to this menu:
File -> Preferences -> Settings
Now you can see 2 window. In the right window add below codes:

{
    "php.validate.executablePath": "C:\\wamp64\\bin\\php\\php7.0.4\\php.exe",
    "php.executablePath": "C:\\wamp64\\bin\\php\\php7.0.4\\php.exe"
}

Just like below image.

enter image description here

NOTICE: This address C:\\wamp64\\bin\\php\\php7.0.4\\php.exe is my php7.exe file address. Replace this address with own php7.exe.

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

9 Comments

Sadly even after doing this the issue continued :/
@Jhollman Did you aware of double black slash ? Did you use exactly ? My problem get solved after using this two code lines.
Thanks. I'm using php-7.2.4-nts-Win32-VC15-x64 in “C:\php” folder and my user settings had just “php.validate.enable”, “php.validate.executablePath” and “php.validate.run”. PHP validation started working when I added the “php.executablePath” config. Now, in my environment the user settings are as follows: { "php.executablePath": "C:/php/php.exe", "php.validate.enable": true, "php.validate.executablePath": "C:/php/php.exe", "php.validate.run": "onType" }.
Is it possible/safe to do this with an external server? what if run php not locally but in a server?
can this be done for an external server? I mean, what if my php bin files live in an external server? I tried to set up the executable path but had no luck
|
51

For those who are using xampp:

File -> Preferences -> Settings

"php.validate.executablePath": "C:\\xampp\\php\\php.exe",
"php.executablePath": "C:\\xampp\\php\\php.exe"

Comments

13

This one also works

  1. Remove the "php.executablePath" line from the VS code settings.

  2. Then add the xampp php path to the System variables

enter image description here

enter image description here

After that restart the Visual Studio Code

Comments

6

After adding php directory in User Settings,

{
    "php.validate.executablePath": "C:/phpdirectory/php7.1.8/php.exe",
    "php.executablePath": "C:/phpdirectory/php7.1.8/php.exe"
}

If you still have this error, please verify you have installed :

To test if you PHP exe is ok, open cmd.exe :

c:/prog/php-7.1.8-Win32-VC14-x64/php.exe --version

If PHP fails, a message will be prompted with the error (missing dll for example).

1 Comment

Please, do not post your code as an image. Use markdown instead.
4

Try this !!!. This will solve your problem for sure!

Method 1 -

Step 1 - Go to 'Environmental Variables'.

Step 2 - Find PATH variable and add the path to your PHP folder.

Step 3 - For 'XAMPP' users put 'C:\xampp\php' and 'WAMP' users put 'C:\wamp64\bin\php\php7.1.9' ) and save.

Method 2-

In VS Code

File -> Preferences -> Settings.

enter image description here

Open 'settings.json' file and put the below codes.

If you are using WAMP put this code and Save.

  "php.validate.executablePath": "C:\\wamp64\\bin\\php\\php7.1.9\\php.exe",
  "php.executablePath": "C:\\wamp64\\bin\\php\\php7.1.9\\php.exe"

If you are using XAMPP put this code and Save.

  "php.validate.executablePath": "C:\\xampp\\php\\php.exe",
  "php.executablePath": "C:\\xampp\\php\\php.exe"

Note - Replace php7.1.9 with your PHP version.

Comments

4

If you are using macOS, you need to install php. You can install it via brew executing the following commands on the terminal:

brew tap homebrew/core

brew install php

After that, you can open VS Code and the error will disappear

Comments

3

On Ubuntu 20.04 the path to executable php is

List all available paths: $ whereis php

One of the paths is: /usr/bin/php

More details on where to add this path: https://code.visualstudio.com/docs/languages/php

Comments

2

For me it was important to delete the "php.executablePath" path from the VS code settings and leave only the path to PHP in the Path variable.

When I had the Path variable together with php.executablePath, an irritating error still occurred (despite the fact that the path to php was correct).

1 Comment

Same here, it's the only thing that worked in Windows.
0

For me this setting was working.
In my windows 8.1 the path for php7 is

C:\user\test\tools\php7\php.exe

settings.json

 {  
 "php.executablePath":"/user/test/tools/php7/php.exe",
 "php.validate.executablePath": "/user/test/tools/php7/php.exe"
 }

see also https://github.com/microsoft/vscode/issues/533

Comments

0

in 2022, I had the same issue - my solution was to set the php.executablePath and php.validate.executablePath to use the folder only (with a trailing slash), omitting the actual executable 'php.exe'.

Comments

0

Well , Everyone has added their answer but I will add one more thing that the chosen answer didn't update.
You can add multiple php executables now ( if code runner extension installed )
A similar issue was pointed out in vscode's github repo #128098 and in #131534 and it was addressed after

VS Code version: 1.59.1 [3866c35]
Release Date : 19th August 2021 or 2021-08-19T11:57:20.140Z

Anyway, so you can now :

  • add your multiple versions/installations of php by clicking on the bottom status bar of vscode, specifically on the version of php you are running ( in this example it is 7.4.3)
    bottom bar of vscode

  • or by editing the code runner extension settings in settings.json(both point to the same file)

settings.json File path in windows and samplecontents:
C:\Users\{Your Name}\AppData\Roaming\Code\User\settings.json

"[html]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "vsicons.dontShowNewVersionMessage": true,
    "debug.onTaskErrors": "showErrors",
    "redhat.telemetry.enabled": false,
    "[cpp]": {
        "editor.wordBasedSuggestions": true,
        "editor.suggest.insertMode": "replace",
        "editor.semanticHighlighting.enabled": true
    },
    "security.workspace.trust.untrustedFiles": "open",
    "totalTypeScript.hideAllTips": false,
    "totalTypeScript.hideBasicTips": false,
    "files.associations": {
        "*.inc": "php"
    },
    "php.executables": {
        "7.4.3":"C:\\xampp\\php\\php.exe",
        "8.1":"C:\\xampp\\php8\\php.exe"
    }
}

Just add

    "php.executables": {
            "7.4.3":"C:\\xampp\\php\\php.exe"
        }

Or

"php.executables": {
            "7.4.3":"C:\\xampp\\php\\php.exe",
            "8.1":"C:\\xampp\\php8\\php.exe"
        }

at the bottom of your settings.json file in vs code

Comments

0

Update (for xampp):

This one worked for me at settings.json add this code:

{
"php.validate.executablePath": "C:\\xampp\\php\\php.exe",
 // "php.executablePath": "C:\\xampp\\php\\php.exe",
 "phpserver.phpPath": "C:\\xampp\\php\\php.exe",
}

doesn't really need the executablePath as other's have mentioned so I omitted it and I added the phpserver.phpPath

Comments

0

macOS users

Extending pableiros's answer here's bit more in-depth explanation for macOS beginner users.

For macOS users who do not have homebrew installed install with homebrew's installation instructions then follow along below.

For macOS users who do not have homebrew's php formulae installed follow pableiros's answer or brew's command here then follow along below.

For macOS users that now have or had brew's php formulae already installed and the notification error persists, open terminal app find your brew install executable application path: by running terminal command which php:

returns

/opt/homebrew/bin/php

Now add that path to your json settings

{
    "php.executablePath": "/opt/homebrew/bin/php"
}

Comments

0

Well I'll throw my variation in. The error VS Code was showing says

'php' binary could not be either found or executed. Make sure PHP is installed, and add path to "php.executables" setting.

I misunderstood the place to add the settings and had it like this:

"php.executables": {    
    "php.executablePath": "/Program Files/PHP/php.exe",
    "php.validate.executablePath": "/Program Files/PHP/php.exe",
    "v8.3": "/Program Files/PHP/php.exe"
},

I looked at the other answers here and other places and realized I might have overthunk it. I changed it to

"php.executablePath": "/Program Files/PHP/php.exe",
"php.validate.executablePath": "/Program Files/PHP/php.exe",
"php.executables": {    
    "v8.3": "/Program Files/PHP/php.exe"
},

And then it started working. Hope this helps someone!

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.