如何在 Windows 上使用命令行访问 PHP?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7307548/
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
How to access PHP with the Command Line on Windows?
提问by JasonDavis
I am trying to learn how to access PHP scripts from the command line (CLI)
我正在尝试学习如何从命令行 (CLI) 访问 PHP 脚本
Below is an image from my attempt, please help. I am running Windows 7
下面是我尝试的图像,请帮助。我正在运行 Windows 7
回答by DaveRandom
You need to add your PHP installation directory to the %PATH%
environment variable, or work from the PHP installation directory.
您需要将 PHP 安装目录添加到%PATH%
环境变量中,或者在 PHP 安装目录下工作。
To add it to path (The best approach - Edited for Windows 7):
将其添加到路径(最佳方法 -针对 Windows 7 编辑):
- Right-click on a
My Computer
icon - Click
Properties
- Click
Advanced system settings
from the left nav - Click
Advanced
tab - Click
Environment Variables
button - In the
System Variables
section, selectPath
(case-insensitive) and clickEdit
button - Add a semi-colon (
;
) to the end of the string, then add the full file system path of your PHP installation (e.g.C:\Program Files\PHP
) - Keep clicking
OK
etc until all dialog boxes have disappeared - Close your command prompt and open it again
- Sorted
- 右键单击一个
My Computer
图标 - 点击
Properties
Advanced system settings
从左侧导航单击- 单击
Advanced
选项卡 - 单击
Environment Variables
按钮 - 在该
System Variables
部分中,选择Path
(不区分大小写)并单击Edit
按钮 ;
在字符串末尾添加分号 ( ),然后添加 PHP 安装的完整文件系统路径(例如C:\Program Files\PHP
)- 继续单击
OK
等直到所有对话框都消失 - 关闭命令提示符并再次打开它
- 已排序
Alternatively, you can run cd <PHP installation path>
before you try and run you command, or call your script like <FULL file system path of php.exe> <path to script>
或者,您可以cd <PHP installation path>
在尝试运行命令之前运行,或者像这样调用脚本<FULL file system path of php.exe> <path to script>
回答by Nabi K.A.Z.
For temporary use, try this: (benefit for use npm
or composer
)
临时使用,试试这个:(有益于使用npm
或composer
)
> SET PATH=c:\wamp\bin\php\php5.3.29\;%PATH%
For test use this:
对于测试使用这个:
> echo %PATH%
c:\wamp\bin\php\php5.3.29\;c:\anothers\;
Now you can access to PHP
command:
现在您可以访问PHP
命令:
> php -v
PHP 5.3.29 (cli)
回答by Mikeys4u
Easy Way: Run CMD then type
简单方法:运行 CMD 然后输入
C:\wamp\bin\php\php5.4.3\php.exe -f "C:\wamp\www\timenow.php"
Change the last part for a different script, and make sure you have the same version php folder as I do. (php5.4.3)
将最后一部分更改为不同的脚本,并确保您拥有与我相同版本的 php 文件夹。(php5.4.3)