PHP7没有安装到命令行

时间:2018-07-27 14:25:35

标签: php command-line path

我最近将PHP 7安装到了计算机上,以帮助使用python创建测试网站。它已全部安装,Visual Studio在其path变量中接受文件。但是,当尝试从命令行运行PHP命令时,它似乎不起作用。

示例:

Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\userName>php -a
'php' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\userName>

我知道这不是命令提示符的问题,因为我已经安装了Java和Python:

Python示例:

C:\Users\userName>py
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print "This works!"
This works!
>>>

同样,我可以运行Java命令:

C:\Users\userName>java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+180)
Java HotSpot(TM) 64-Bit Server VM (build 9+180, mixed mode)

C:\Users\userName>

我找到了解决该问题的临时方法,这需要每次我想编写PHP命令时都设置一个路径:

C:\Users\userName>path C:\Program Files\PHP7

C:\Users\userName>php -a
Interactive shell

php > echo "This works!";
This works!
php >  

任何有关如何永久解决此问题的答案将不胜感激!

1 个答案:

答案 0 :(得分:3)

如果要直接通过命令“ php”使用它,则必须将路径环境变量设置为php。

我认为这会对您有所帮助:How to access PHP with the Command Line on Windows?