问题
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
Any advice would be appreciated.
回答1:
You can set environment variables as mentioned in the other answers (like here)
or
you can open Start > CMD as administrator and write
C:\xampp\php phpfile.php
回答2:
XAMPP does not have a pre build console to run php
or mysql
commands, so, you have to add to windows PATH
environment variables, these 2: ;C:\xampp\mysql\bin;C:\xampp\php;
Then you should be able to execute php
and mysql
commands from the CMD.
UPDATE
I tested it, and it works.
回答3:
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 variable as mentioned in the answer by w0rldart .
In this case(after seting envmnt var) we may run the phpFile by opening start >> CMD and typing commands like,
php.exe <path to file location>
or
php <path to file location>
example:
php.exe C:\xampp\htdocs\test.php
you can open Start >> CMD as 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.php
or
C:\xampp\php\php C:\xampp\htdocs\test.php
Hopes this will help somebody.
回答4:
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.
Once you have done that you can run using the command from the start->command line as below
php <path to file location>
回答5:
Run PHP file from command Promp.
Please set Environment Variable as per below mention steps.
- Right Click on MY Computer Icon 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.exe file is available - For example if XAMPP install in to C: drive then Path is "C:\xampp\php"
- After set path Click Ok and Apply.
Now open Command prompt where your source file are available and run command "php test.php"
回答6:
Like all other had said above, you need to add path. But not sure for what reason if I add C:\xampp\php
in path of System Variable won't work but if I add it in path of User Variable work fine.
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
回答7:
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.
回答8:
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.
来源:https://stackoverflow.com/questions/10753024/how-to-access-the-command-line-for-xampp-on-windows