如何在 Windows 上使用命令行访问 PHP?
我正在尝试学习如何从命令行 (CLI) 访问 PHP 脚本
I am trying to learn how to access PHP scripts from the command line (CLI)
下面是我尝试的图片,请帮忙.我运行的是 Windows 7
Below is an image from my attempt, please help. I am running Windows 7
推荐答案
您需要将您的 PHP 安装目录添加到 %PATH%
环境变量中,或者在 PHP 安装目录下工作.
You need to add your PHP installation directory to the %PATH%
environment variable, or work from the PHP installation directory.
将其添加到路径(最佳方法 - 为 Windows 7 编辑):
To add it to path (The best approach - Edited for Windows 7):
- 右键单击
我的电脑
图标 - 点击
属性
- 点击左侧导航栏中的
Advanced system settings
- 点击
Advanced
标签 - 点击
环境变量
按钮 - 在
System Variables
部分,选择Path
(不区分大小写)并点击Edit
按钮 - 在字符串末尾添加分号 (
;
),然后添加 PHP 安装的完整文件系统路径(例如C:Program FilesPHP
代码>) - 继续点击
OK
等直到所有对话框消失 - 关闭命令提示符并再次打开
- 已排序
- 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 FilesPHP
) - Keep clicking
OK
etc until all dialog boxes have disappeared - Close your command prompt and open it again
- Sorted
或者,您可以在尝试运行命令之前运行 cd
,或者像
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>
相关文章