“无法验证 php 文件。未找到 php 程序”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34182067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:48:48  来源:igfitidea点击:

"Cannot validate the php file. The php program was not found"

phpvisual-studio-code

提问by Ari4

I'm a beginner in PHP and want to use the VS Code editor. However, when I first save my php file I get this message:

我是 PHP 初学者,想使用 VS Code 编辑器。但是,当我第一次保存我的 php 文件时,我收到以下消息:

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

无法验证 php 文件。找不到 php 程序。使用'php.validate.executablePath'设置来配置'php'的位置

What is the problem?

问题是什么?

回答by Ari4

First, go to File->Preferences->User settings, A window will come like below image.

首先,转到 File->Preferences->User settings,会出现一个如下图所示的窗口。

enter image description here

在此处输入图片说明

Now change the setting.jsonfile like below image and save:

现在更改setting.json文件,如下图所示并保存:

enter image description here

在此处输入图片说明

If PHP is not installed in your system, download php from here: windows.php.net/download, unzip to C:drive, set "php.validate.executablePath": "C://path.to.your.php.folder//php.exe"

如果您的系统中没有安装 PHP,请从这里下载 php:windows.php.net/download,解压到C:驱动器,设置"php.validate.executablePath": "C://path.to.your.php.folder//php.exe"

If php is installed in your system simply set the path of your php.exefile like below:

如果系统中安装了 php,只需设置php.exe文件路径,如下所示:

"php.validate.executablePath": "C://path.to.your.php.folder//php.exe"

hint: In my case I use XAMPP which is installed in the D: drive, so my setting is below

提示:就我而言,我使用安装在 D: 驱动器中的 XAMPP,所以我的设置如下

"php.validate.executablePath": "D://xampp//php//php.exe"

"php.validate.executablePath": "D://xampp//php//php.exe"

Mind the double forward slashes.

注意双正斜杠

回答by Nidhin

I solved it by adding lines

我通过添加行解决了它

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

回答by sgtkuncoro

this is work for me.

这对我来说是工作。

if you have installed php, please add path of installation php on path windows enviroment variable.

如果你已经安装了php,请在windows环境变量中添加安装php的路径。

if you not install php yet, please follow this step:

如果您还没有安装 php,请按照以下步骤操作:

  1. Install php and copy path installation. ex : C:\XAMPP\php
  2. go to System > Advanced System setting > Enviroment Variable > User Variable > Path > Edit > New > paste the path
  1. 安装php并复制路径安装。例如:C:\XAMPP\php
  2. 转到系统 > 高级系统设置 > 环境变量 > 用户变量 > 路径 > 编辑 > 新建 > 粘贴路径

restart vscode

重启 vscode

回答by user3617558

there is a fast way for fixing this, just

有一个快速的方法来解决这个问题,只是

  1. Search in Cortana : web
  2. Open Microsoft Web Platform Installer
  3. Search in Microsoft Web for "php"
  4. install one of php versions like php 7.0.5 or php 5.6
  5. if your install be successful, now your system have php and you won't see php error in visual code.
  1. 在 Cortana 中搜索:web
  2. 打开Microsoft Web 平台安装程序
  3. 在 Microsoft Web 中搜索“php”
  4. 安装 php 版本之一,如 php 7.0.5 或 php 5.6
  5. 如果您的安装成功,现在您的系统有 php 并且您不会在可视代码中看到 php 错误。

回答by eliasmaxil

Perhaps it is a syntaxis issue. After many tries I found that the command had to be written

也许这是一个语法问题。经过多次尝试,我发现必须编写命令

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

(with 2 backslashes). I noticed that many answers said that a normal slash (/) or just one back slash worked as well. I have the Visual Studio Code version 1.17.0-insider x64.

(带 2 个反斜杠)。我注意到许多答案都说普通斜杠 (/) 或仅一个反斜杠也有效。我有 Visual Studio Code 版本 1.17.0-insider x64。

The solution worked independently of the location of the executable file. Which in my case was located in C:\xampp\php\php.exe and ?C:\Program Files\PHP\v7.1\php.exe.

该解决方案的工作独立于可执行文件的位置。在我的情况下,它位于 C:\xampp\php\php.exe 和 ?C:\Program Files\PHP\v7.1\php.exe。

回答by Tobiah Zarlez

VS Code is looking to validate your code using php, and it is not finding php installed on your system.

VS Code 正在寻找使用 php 验证您的代码,但它没有找到您的系统上安装的 php。

If you install php to your path (That is to say, in a command prompt window you can type "php" in any folder and something will happen), everything should work.

如果您将 php 安装到您的路径(也就是说,在命令提示符窗口中,您可以在任何文件夹中键入“php”,然后就会发生一些事情),一切都应该可以正常工作。

Otherwise, you can do one of two things:

否则,您可以执行以下两种操作之一:

  1. Set the "php.validate.executablePath" setting in VS Code to point to the php executable on your system, wherever it may be.
  1. 在 VS Code 中设置“php.validate.executablePath”设置以指向系统上的 php 可执行文件,无论它在哪里。

OR

或者

  1. Ignore the error, but you won't get proper error detection as you code.
  1. 忽略错误,但在编码时不会得到正确的错误检测。

For more information, see this: https://code.visualstudio.com/Updates#_language-php

有关更多信息,请参阅:https: //code.visualstudio.com/Updates#_language-php

回答by Mastro

Also, that only works if you open a folder in VS Code, you can't set it up to view a single file. Since VC creates a ".vscode" folder with a settins.json inside of it when you edit Preferences > Workspaces. This is where you could specify the php.validate.executablePath.

此外,这仅在您在 VS Code 中打开文件夹时才有效,您无法将其设置为查看单个文件。由于 VC 会在您编辑首选项 > 工作区时创建一个“.vscode”文件夹,其中包含一个 settins.json。您可以在此处指定 php.validate.executablePath。

So keep that in mind, if you just open a single file, you can't use that functionality but it will still show the warning. Instead open the folder the file is in.

因此请记住,如果您只打开一个文件,则无法使用该功能,但它仍会显示警告。而是打开文件所在的文件夹。

If you want to never have to worry about it, then modify your %path% environment variable to include the folder that php.exe is in.

如果您不想担心,请修改您的 %path% 环境变量以包含 php.exe 所在的文件夹。

回答by Marcel

First, go to File->Preferences->settings->User settingstab->extensions->from the drop down select php->on the right pane under PHP ? Validate: Executable Pathselect edit in settings.json.

首先,转到 File-> Preferences-> settings-> User settingstab-> extensions-> 从下拉列表中选择php-> 在PHP下的右侧窗格中验证:在 settings.json 中选择编辑可执行路径

Then set the path as your case may be e.g for a xamp user who installed xammp on c drive you will have:

然后根据您的情况设置路径,例如,对于在 c 驱动器上安装 xampp 的 xamp 用户,您将拥有:

"php.validate.executablePath": "c:\xampp\php\php.exe"

"php.validate.executablePath": "c:\xampp\php\php.exe"

If php is installed in your system independently or by other means simply set the path of your php.exe file like below:

如果 php 是独立安装在您的系统中或通过其他方式简单地设置您的 php.exe 文件的路径,如下所示:

"php.validate.executablePath": "C://path.to.your.php.folder//php.exe"

"php.validate.executablePath": "C://path.to.your.php.folder//php.exe"

回答by Mohammad

I was in the same situation. I'm using PHP through a docker (using Visual Studio Code). I didn't want to install PHP on my PC.

我处于同样的情况。我正在通过 docker(使用 Visual Studio Code)使用 PHP。我不想在我的 PC 上安装 PHP。

The solution that worked for me was to download a portableserver that executes PHP (www.uwamp.com). You will download it as a zip file (no installation or configuration needed) and save it somewhere on your PC.

对我有用的解决方案是下载一个执行 PHP (www.uwamp.com)的便携式服务器。您将其下载为 zip 文件(无需安装或配置)并将其保存在 PC 上的某个位置。

Follow these steps:

按着这些次序:

  • download zip file from: https://www.uwamp.com/file/UwAmp.zip
  • unzip and save to any folder on your PC like: C:\Data\UwAmp
  • get the url to the php.exe file inside UwAmp > C:\Data\UwAmp\bin\php\php-7.0.3\php.exe
  • open Visual Studio Code and go to: File > Preferences > Settings > Open Settings (JSON) (you will have to click the icon at the top right corner)
    List item
  • Add following reference to the bottom of the settings.jsonfile:
    "php.validate.executablePath": "C:\Data\UwAmp\bin\php\php-7.0.3\php.exe"
  • save (you may possibly have to restart Visual Studio Code)
  • 从以下位置下载 zip 文件:https: //www.uwamp.com/file/UwAmp.zip
  • 解压并保存到 PC 上的任何文件夹,例如:C:\Data\UwAmp
  • 获取 UwAmp > C:\Data\UwAmp\bin\php\php-7.0.3\php.exe 中 php.exe 文件的 URL
  • 打开 Visual Studio Code 并转到:文件 > 首选项 > 设置 > 打开设置 (JSON)(您必须单击右上角的图标)
    项目清单
  • settings.json文件底部添加以下引用:
    "php.validate.executablePath": "C:\Data\UwAmp\bin\php\php-7.0.3\php.exe"
  • 保存(您可能需要重新启动 Visual Studio Code)

This is not the exact solution you (and myself) was aiming for, but no PHP was installed and configured on the PC and it's easy to clean up (just delete the UwAmp folder and remove the line at settings.json) when done.

这不是您(和我自己)想要的确切解决方案,但是没有在 PC 上安装和配置 PHP,并且完成后很容易清理(只需删除 UwAmp 文件夹并删除settings.json中的行)。