PHP executable not found. Install PHP 7 and add it to your PATH or set the php.executablePath setting
Visual Studio-CodePhp 7Visual Studio-Code Problem Overview
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.
Visual Studio-Code Solutions
Solution 1 - Visual Studio-Code
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.
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
.
Solution 2 - Visual Studio-Code
For those who are using xampp:
File -> Preferences -> Settings
"php.validate.executablePath": "C:\\xampp\\php\\php.exe",
"php.executablePath": "C:\\xampp\\php\\php.exe"
Solution 3 - Visual Studio-Code
This one also works
-
Remove the "php.executablePath" line from the VS code settings.
-
Then add the xampp php path to the System variables
After that restart the Visual Studio Code
Solution 4 - Visual Studio-Code
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 :
-
64-bit or 32-bit version of php (x64 or x86), depending on your OS;
-
some librairies like Visual C++ Redistributable for Visual Studio 2015 : http://www.microsoft.com/en-us/download/details.aspx?id=48145;
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).
Solution 5 - Visual Studio-Code
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.
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.
Solution 6 - Visual Studio-Code
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
Solution 7 - Visual Studio-Code
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
Solution 8 - Visual Studio-Code
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).
Solution 9 - Visual Studio-Code
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"
}