61

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

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
Nifal Nizar
  • 895
  • 1
  • 8
  • 17
  • 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. – Hrvoje T Dec 05 '18 at 20:49

13 Answers13

96

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.

Bala
  • 618
  • 5
  • 21
ops
  • 2,023
  • 18
  • 21
  • 1
    Sadly even after doing this the issue continued :/ – Douglas Gaskell Apr 05 '17 at 20:41
  • @Jhollman Did you aware of double black slash ? Did you use exactly ? My problem get solved after using this two code lines. – Mohan Perera May 09 '18 at 04:05
  • 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" }`. – Fernando Brustolin May 14 '18 at 13:49
  • Is it possible/safe to do this with an external server? what if run php not locally but in a server? – MrCujo May 25 '18 at 17:09
  • 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 – MrCujo Jun 05 '18 at 23:00
  • For those Xampp user and has multiple php version installed can see the running php version using the **click on explorer it will open up the exact folder of xampp installed folder > php folder** . – shaan gola Nov 20 '18 at 05:27
  • escaping slash helps ! that's what was missing even after i entered the path. – Reejesh PK Aug 31 '19 at 06:20
  • For some reason, if you put PHP in your PATH and have the "php.executablePath" & "php.validate.executablePath" previously set then you'll get this exact error. After testing PHP with "php -v" and confirming it's in the PATH the only fix I could come up was removing the "php.executablePath" & "php.validate.executablePath" from the settings.json. – thvs86 Mar 17 '20 at 11:22
  • can I use shortcut for this? – Jenuel Ganawed Feb 23 '23 at 06:15
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"
Sahin Erbay
  • 994
  • 2
  • 12
  • 24
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

Arosha De Silva
  • 597
  • 8
  • 18
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).

rcperso
  • 490
  • 5
  • 10
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

pableiros
  • 14,932
  • 12
  • 99
  • 105
3

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.

Kusal Kithmal
  • 1,255
  • 1
  • 10
  • 25
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

Bartek
  • 810
  • 7
  • 9
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).

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

Competo
  • 133
  • 1
  • 11
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'.

noseve
  • 11
  • 3
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

Lucifer
  • 79
  • 6
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

mhermano
  • 89
  • 9
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"
}