Vscode: PHP executable not found. You need PHP 7 installed and in your PATH

Created on 7 Oct 2016  路  20Comments  路  Source: microsoft/vscode

  • VSCode Version: 1.5.3
  • OS Version: Windows 10 x64

Hi, Humans.
Steps to Reproduce:

  1. I installed VS code and then the problem started.
  2. I opened VS and then I installed ftp-simple extension.
  3. I opened project next I opened file with php extension.
  4. Then I saw this info

Cannot validate the php file. The php program was not found. Use the 'php.validate.executablePath' setting to configure the location of 'php'

I said okey, and I opened

FIle > Preferences > User Settings > Settings.json

I added this line

// Points to the php executable.
"php.validate.executablePath":"C:\OpenServer\modules\php\PHP-7-x64\php.exe",

The problem is gone.

  1. But then I saw new error

PHP executable not found. You need PHP 7 installed and in your PATH

How to solve this error I don't know. Please, help me.

*question php

Most helpful comment

I had the same error, so I removed the executablePath setting and did the following steps:
Windows search for "environment"
click on edit environment variables (for your acount)
click on the "path" variable and press "Edit..."
click on "new"
write down the path to your php 7 files, for example: D:\php7

(in your case it should be: C:\OpenServer\modules\php\PHP-7-x64 )

When starting visual studio code the error should be gone.

All 20 comments

I am having the same problem. I wanted to use the IntelliSense extension for VS Code editor and when I made the path point to version 7 of the php.exe I got from wamp I got the same error. It worked fine with the version 5.

I had the same error, so I removed the executablePath setting and did the following steps:
Windows search for "environment"
click on edit environment variables (for your acount)
click on the "path" variable and press "Edit..."
click on "new"
write down the path to your php 7 files, for example: D:\php7

(in your case it should be: C:\OpenServer\modules\php\PHP-7-x64 )

When starting visual studio code the error should be gone.

I did change the environment variable path. Still getting the error.

There are multiple failure modes here, and they all have similar messages, so let's try and be specific about which one we're talking about.

| # | Error message | Source | Resolution |
| --- | --- | --- | --- |
| 1 | Cannot validate the php file. The php program was not found. Use the 'php.validate.executablePath' setting to configure the location of 'php' | built-in PHP validation provider | Set php.validate.executablePath in FIle > Preferences > User Settings > Settings.json or add php to your PATH, which we'll fall back to if php.validate.executablePath is not set |
| 2 | Failed to run php using path: {0}. Reason is unknown. | built-in PHP validation provider | ??? - try running My\php\validate\executablePath\php.exe -l -n -d log_errors=Off -f myFile.php, and paste the output |
| 3 |

  1. PHP executable not found. You need PHP 7 installed and in your PATH
  2. The language server needs at least PHP 7 installed and in your PATH. Version found: ' + version
  3. Error spawning PHP: ' + err.message
  4. Error parsing PHP version. Please check the output of php --version
| vscode-php-intellisense extension | Add the path to PHP7 to your environment variables, run where php and php --version to verify. You'll also need to relaunch VSCode (and the cmd line you are launching it from if you changed the environment variables) |

So @FAST-JE, it looks like you ran into _#_1 first, you resolved it by adding php.validate.executablePath, and then ran into _#_3.1, so it would be great if you could verify that adding PHP7 to your env. variables resolves the issue. There's also an issue open to make the intellisense extension respect php.validate.executablePath https://github.com/felixfbecker/vscode-php-intellisense/issues/11, cc @felixfbecker

@dkimery256 I have no idea what error you're running into, but hopefully the table above will help narrow it down :smiley:

@dkimery256 oh, and one more thing! Just a hunch... you mentioned you changed the PATH from PHP5 to PHP7, which implies that this is not a new environment config, which implies that you've likely customized your PHP5 ini file, which implies that your PHP7 ini file might have different settings than your PHP5 ini file, which implies that something about those settings might have an effect on whether php commands execute as expected in VSCode or the php intellisense extension, which implies that WAMP has different default settings than "vanilla" PHP that somehow impact basic execution, which implies that there's a good chance that it's related to some virtual filepath config, as is often the case with "cooked" environment setups.

So in summary, if you get errors after running php --version or php -l -n -d log_errors=Off -f myFile.php, also check your php.ini file, and, in particular, look out for potentially invalid filepaths.

The message is indeed caused by my extension, thanks for clearing that up to detailed @mousetraps.

I'm haven't decided yet what settings "namespace" I should use for PHP IntelliSense. My thought was that the built-in PHP support hopefully soon gets removed from core? Because the validation and completion is conflicting with PHP IntelliSense and causing duplicate entries. Which is one of the reason why I thought it might be a good idea to use a generic php.executablePath setting, instead of php.intellisense.executablePath. Would be nice to hear some opinions on this from VS Code devs.

@mousetraps I Added the path to PHP7 to your environment variables screenshot
and screenshot settings.json
The problem is not solved.

@FAST-JE You need to add the path of the directory, not the path to the exe. If you still experience problems please open an issue at my repository or chat with me on Gitter so we don't spam the VS Code dev folks here.

I'm haven't decided yet what settings "namespace" I should use for PHP IntelliSense. My thought was that the built-in PHP support hopefully soon gets removed from core? Because the validation and completion is conflicting with PHP IntelliSense and causing duplicate entries. Which is one of the reason why I thought it might be a good idea to use a generic php.executablePath setting, instead of php.intellisense.executablePath. Would be nice to hear some opinions on this from VS Code devs.

@felixfbecker I like the idea of using php.executablePath rather than php.validate.executablePath both for the sake of simplification and because that appears to be how the broader ecosystem has tended to evolve (this is what both the Go and Python extensions do).

Also agreed it would make sense to remove the built-in PHP completions support, because it appears to be the only language VSCode includes deeper-than-syntax-higlighting support for that is not one of the languages that VSCode is actually written in. So no guarantees just yet, but I'll look into the potential implications this week. In the meantime, is there anything you can do to filter out duplicates in the completion list? (or better yet, just feel free to tag me on any open discussions in your repo so we don't clutter up this thread)

Closing this thread, as the primary issue has been resolved. @felixfbecker let's chat further about the executablePath stuff on a separate thread. One of the challenges will be figuring out how to resolve discrepancies with different versions of PHP between different extensions. Would be curious to hear your thoughts.

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

I got this working some time ago, forgot about the thread, sorry. My problem was that I had my path set right in VS-Code, but my system var path I had included the php.exe in the path and that was causing issues. Once I pointed my system var to the directory alone and not the exe, everything worked just fine. Thanks for all the suggestions.

For anyone having this issue, it is due the PATH, you must change your environment PATH.
on Linux: nano ~/.bash_profile
On Windows: Edit environment Variables -> System Variables -> Path. Change the priority
vscodeerror

SOLVED:
Added in Settings:

{
    "php.executablePath": "C:\\PHP_7\\php.exe",
    "php.validate.executablePath": "C:\\PHP_7\\php.exe",
    ...
}

For Mac users:
This is what worked for me.
{
"php.executablePath": "/absolute path to your php 7 installation"
}

You installed PHP IntelliSense extension, and this error because of it.
So if you want to fix this problem go to this menu:
File -> Presences -> User 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"
}

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.

Font: https://stackoverflow.com/questions/40287927/php-executable-not-found-install-php-7-and-add-it-to-your-path-or-set-the-php-e/45784662#45784662

i've added php path to Windows Path then error disappears.

When I added the PHP execuable to the Path variable in windows it fixed the error for me.

@Firegarden Can you ensure when you open a command prompt, that you can type php -v and get your current php version?

Wy not just add a 'dont show option' for this function? See the neovim plugin example: "vim.disableAnnoyingNeovimMessage": true

Was this page helpful?
0 / 5 - 0 ratings