简体   繁体   English

PHP 在命令提示符中未被识别为内部或外部命令

[英]PHP is not recognized as an internal or external command in command prompt

I got the following error when I run a command with php当我使用php运行命令时出现以下错误

C:\xampp\htdocs>php
'php' is not recognized as an internal or external command,
operable program or batch file.

I don't get any error when I run the command with php in following path:当我在以下路径中使用php运行命令时,我没有收到任何错误:

C:\xampp\php>php  //do not got error here

Why I get this error?为什么我会收到此错误?

'php' is not recognized as an internal or external command, operable program or batch file. 'php' 不是内部或外部命令,也不是可运行的程序或批处理文件。

Add C:\\xampp\\php to your PATH environment variable.( My Computer->properties -> Advanced system setting-> Environment Variables->edit path )C:\\xampp\\php添加到您的PATH环境变量中。(我的电脑->属性->高级系统设置->环境变量->编辑路径

Then close your command prompt and restart again.然后关闭命令提示符并再次重新启动。

Note: It's very important to close your command prompt and restart again otherwise changes will not be reflected.注意:关闭命令提示符并重新启动非常重要,否则将不会反映更改。

You need to Go to My Computer->properties -> Advanced system setting您需要转到我的电脑-> 属性-> 高级系统设置

Now click on Environment Variables..现在点击环境变量..

在此处输入图片说明

Add ;C:\\xampp\\php in path variable value路径变量值中添加;C:\\xampp\\php

在此处输入图片说明

Now restart command prompt DONE!现在重新启动命令提示符完成!

Note: Make sure you run CMD via run as administrator注意:确保以管理员身份运行 CMD

You just need to a add the path of your PHP file.您只需要添加PHP文件的路径。 In case you are using wamp or have not installed it on the C drive.如果您正在使用wamp或尚未将其安装在 C 驱动器上。

图为如何找到路径

Set "C:\\xampp\\php" in your PATH Environment Variable .在 PATH Environment Variable 中设置"C:\\xampp\\php" Then restart CMD prompt.然后重新启动 CMD 提示。

Is your path correctly configured?你的路径配置正确吗?

In Windows, you can do that as described here:在 Windows 中,您可以按照此处所述进行操作:

http://www.computerhope.com/issues/ch000549.htm http://www.computerhope.com/issues/ch000549.htm

您需要将C:\\xampp\\php添加到您的PATH Environment Variable ,只有在此之后您才能从php_home外部执行php命令行。

I also got the following error when I run a command with PHP , I did the solution like that:当我使用PHP运行命令时,我也遇到了以下错误,我是这样解决的:

  1. From the desktop, right-click the Computer icon.在桌面上,右键单击计算机图标。
  2. Choose Properties from the context menu.从上下文菜单中选择属性。
  3. Click the Advanced system settings link.单击高级系统设置链接。
  4. Click Environment Variables.单击环境变量。 In the section System Variables, find the PATH environment variable and select it.在 System Variables 部分,找到 PATH 环境变量并选择它。 Click Edit.单击编辑。 If the PATH environment variable does not exist, click New.如果 PATH 环境变量不存在,请单击新建。
  5. In the Edit System Variable window, Add C:\\xampp\\php to your PATH Environment Variable.在 Edit System Variable 窗口中,将C:\\xampp\\php添加到您的PATH环境变量。

Very important note: restart command prompt非常重要的提示:重启命令提示符

在此处输入图片说明 在此处输入图片说明

Here what I DO on MY PC I install all software that i usually used in G: partian not C: if my operating system is fall (win 10) , Do not need to reinstall them again and lost time , Then How windows work it update PATH automatic if you install any new programe or pice of softwore ,这是我在我的 PC 上所做的,我安装了我通常在 G 中使用的所有软件:partian 而不是 C:如果我的操作系统失败(win 10),不需要再次重新安装它们并浪费时间,那么 Windows 是如何工作的呢?如果您安装任何新程序或软件,路径自动,

SO所以

I must update PATH like these HERE!我必须在这里更新 PATH ! all my software i usually used我常用的所有软件

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;G:\HashiCorp\Vagrant\bin;G:\xampp\php;G:\xampp\mysql\bin;G:\Program Files (x86)\heroku\bin;G:\Program Files (x86)\Git\bin;G:\Program Files (x86)\composer;G:\Program Files (x86)\nodejs;G:\Program Files (x86)\Sublime Text 3;G:\Program Files (x86)\Microsoft VS Code\bin;G:\Program Files (x86)\cygwin64\bin

在此处输入图片说明

Extra info:额外信息:

If you are using PhpStorm as IDE, after updating the path variable you need to restart PhpStorm so that it takes effect.如果你使用 PhpStorm 作为 IDE,更新路径变量后需要重启 PhpStorm 才能生效。

Restarting terminal window was not enough for me.重新启动终端窗口对我来说还不够。 (PhpStorm 2020.3.2) (PhpStorm 2020.3.2)

I Have to face the same problem which I solve check my answer.
Follow these steps:
1)System Properties
2)Advanced
3)Environmental Variables
4)Path 
5)add the installation path of xammp/wamp like in my case the path is(E:\xammp\php)
5)Ok
6)Restart cmd
7)check the version of PHP(PHP --version)

在此处输入图片说明

I faced this issue even with a properly set up windows environment variable.即使正确设置了 Windows 环境变量,我也遇到了这个问题。 I just needed to close and restart the terminal to solve it.我只需要关闭并重新启动终端来解决它。

The previous answers about adding the path to the Env Var are correct, but my case was different.之前关于将路径添加到 Env Var 的答案是正确的,但我的情况不同。

I needed to downgrade my PHP version to 5 in order to update an old application.我需要将我的 PHP 版本降级到 5 才能更新旧应用程序。

I was using the following combination: MAMP, PhpStorm, the Environment Variable Path was set properly to the MAMP PHP version that I was using我使用了以下组合:MAMP、PhpStorm,环境变量路径已正确设置为我使用的 MAMP PHP 版本

  • The error was showing in PhpStorm's Terminal该错误显示在 PhpStorm 的终端中
  • The error was due to the php.ini file using # in the comment该错误是由于 php.ini 文件在注释中使用了 #
  • After I replaced "#" by ";"在我用“;”替换“#”之后I restarted PhpStorm and recognized the PHP version and the command "php -v" worked again我重新启动了 PhpStorm 并识别出 PHP 版本,命令“php -v”再次运行

Laragon users<\/strong> Laragon 用户<\/strong>

you will find your PHP folder in the bin folder of laragon.你会在 laragon 的 bin 文件夹中找到你的 PHP 文件夹。 goto your desired PHP version folder and copy the location.转到您想要的 PHP 版本文件夹并复制该位置。 for me it was:对我来说是:

C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64

在我的情况下,问题出在路径中,我给出了php.exe<\/code>的路径,这是错误的,我必须编写根文件夹的路径......

"

For Laragon:对于拉拉贡:

First, download your PHP from [https:\/\/windows.php.net\/download\/] then unzip your file -> copy folder -> paste this direction:首先,从 [https:\/\/windows.php.net\/download\/] 下载您的 PHP,然后解压缩您的文件 -> 复制文件夹 -> 粘贴此方向:

C:\\laragon\\bin\\php`Your folder` C:\\laragon\\bin\\php`你的文件夹`

search from windows从窗口搜索

Edit the system environment variables and then open it.编辑系统环境变量,然后打开它。 编辑系统环境变量<\/a>

<\/blockquote>

Click Environment variables...单击环境变量... 环境变量<\/a>

Click path and Edit单击路径和编辑

环境变量添加<\/a>

Click New and add the php.exe path like: C:\\laragon\\bin\\php`Your folder`单击新建并添加 php.exe 路径,如:C:\\laragon\\bin\\php`Your folder`

and then press OK for all steps.然后按 OK 执行所有步骤。

restart laragon and vscode重启 laragon 和 vscode

and our problem is already solved.我们的问题已经解决了。

"

In latest Xampp 8.1.2 PHP path is changed to this below: Set it in your PATH variable.在最新的 Xampp 8.1.2 PHP 路径更改为以下内容: 在 PATH 变量中设置它。

C:\xampp\php\windowsXamppPhp

I restarted CMD program it solves my problem我重新启动了 CMD 程序,它解决了我的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM