php 如何在 Windows 上访问 xampp 的命令行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10753024/
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 the command line for xampp on windows
提问by Somk
I am running Xampp on my Windows 7 machine and was wondering if and how I could run commands for xampp via a command line. commands like php phpfile.php
我在我的 Windows 7 机器上运行 Xampp,想知道我是否以及如何通过命令行运行 xampp 的命令。像 php phpfile.php 这样的命令
Any advice would be appreciated.
任何意见,将不胜感激。
回答by Alex
XAMPP does not have a pre build console to run phpor mysqlcommands, so, you have to add to windows PATHenvironment variables, these 2: ;C:\xampp\mysql\bin;C:\xampp\php;
XAMPP 没有要运行的预构建控制台php或mysql命令,因此,您必须添加到 windowsPATH环境变量,这两个:;C:\xampp\mysql\bin;C:\xampp\php;
Then you should be able to execute phpand mysqlcommands from the CMD.
然后你应该能够从 CMD执行php和mysql命令。
UPDATE
更新
I tested it, and it works.
我测试了它,它有效。
回答by Micheal Mouner Mikhail Youssif
回答by skt
Thank you guys for this answers. But I think the accepted answer needs more clarity, As i found difficulty in getting the solution.
谢谢你们的回答。但我认为接受的答案需要更清晰,因为我发现很难找到解决方案。
We may set the environment variableas mentioned in the answer by w0rldart .
In this case(after seting envmnt var) we may run the phpFile by opening start >> CMDand typing commands like,
php.exe <path to file location>or
php <path to file location>example:
php.exe C:\xampp\htdocs\test.phpyou can open Start >> CMDas administrator and write like
<path to php.exe in xampp's php folder> <path to file location>example:
C:\xampp\php\php.exe C:\xampp\htdocs\test.phpor
C:\xampp\php\php C:\xampp\htdocs\test.php
我们可以设置w0rldart 回答中提到的环境变量。
在这种情况下(在设置envmnt var 之后)我们可以通过打开start >> CMD并键入命令来运行 phpFile,例如,
php.exe <path to file location>或者
php <path to file location>例子:
php.exe C:\xampp\htdocs\test.php您可以以管理员身份打开开始>> CMD并像这样写
<path to php.exe in xampp's php folder> <path to file location>例子:
C:\xampp\php\php.exe C:\xampp\htdocs\test.php或者
C:\xampp\php\php C:\xampp\htdocs\test.php
Hopes this will help somebody.
希望这会帮助某人。
回答by HopeKing
In case some one wants to know how to set up Environment variables
如果有人想知道如何设置环境变量
- Click on the windows button on the bottom left and go to System
- Click the Advanced System Settings link in the left column
- In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
- In the Environment Variables window , highlight the Path variable in the "System variables" section and click the Edit button. Add the path lines with the paths you want the computer to access.
- 点击左下角的windows按钮,进入系统
- 单击左栏中的高级系统设置链接
- 在“系统属性”窗口中,单击“高级”选项卡,然后单击该选项卡底部附近的“环境变量”按钮。
- 在“环境变量”窗口中,突出显示“系统变量”部分中的 Path 变量,然后单击“编辑”按钮。添加带有您希望计算机访问的路径的路径行。
Once you have done that you can run using the command from the start->command line as below
完成后,您可以使用 start-> 命令行中的命令运行,如下所示
php <path to file location>
回答by Kaushik Andani
Run PHP file from command Promp.
从命令 Promp 运行 PHP 文件。
Please set Environment Variableas per below mention steps.
请按照以下提到的步骤设置环境变量。
- Right Click on MY ComputerIcon and Click on Properties or Go to "Control Panel\System and Security\System".
- Select "Advanced System Settings"and select "Advance"Tab
- Now Select "Environment Variable"option and select "Path"from "System Variables"and click on "Edit" button
- Now set path where php.exefile is available - For example if XAMPPinstall in to C: drive then Path is "C:\xampp\php"
- After set path Click Ok and Apply.
- 右键单击“我的电脑”图标并单击“属性”或转到“控制面板\系统和安全\系统”。
- 选择“高级系统设置”并选择“高级”选项卡
- 现在选择“环境变量”选项并从“系统变量”中选择“路径”,然后单击“编辑”按钮
- 现在设置php.exe文件可用的路径- 例如,如果XAMPP安装到 C: 驱动器,则路径为“C:\xampp\php”
- 设置路径后单击“确定”并“应用”。
Now open Command prompt where your source file are available and run command "php test.php"
现在打开您的源文件可用的命令提示符并运行命令“php test.php”
回答by cjmling
Like all other had said above, you need to add path. But not sure for what reason if I add C:\xampp\phpin path of System Variablewon't workbut if I add it in path of User Variablework fine.
就像上面所有其他人所说的一样,您需要添加路径。但不确定是什么原因,如果我添加系统变量的C:\xampp\php路径将不起作用,但如果我将它添加到用户变量的路径工作正常。
Although I had added and using other command line tools by adding in system variables work fine
虽然我通过添加系统变量来添加和使用其他命令行工具工作正常
So just in case if someone had same problem as me. Windows 10
所以以防万一有人和我有同样的问题。视窗 10
回答by Sebastian Viereck
Please renember: When you change the path variable, you need to restart the console otherwise the path variable is not updated and does not seem to work.
请重新注册:当您更改路径变量时,您需要重新启动控制台,否则路径变量不会更新并且似乎不起作用。
回答by savage_floweed
Xampp has the php application under: C:\xampp\php file directory ... if you input C:\xampp\php\php in CMD it should enter the php application.
Xampp 的 php 应用程序位于: C:\xampp\php 文件目录...如果您在 CMD 中输入 C:\xampp\php\php 它应该进入 php 应用程序。


