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.
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.
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
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.
I tested it, and it works.
Control Panel\System and Security\System > Advanced system settings > Environment Variables
–
Contraption 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
C:\xampp\php\php phpfile.php
–
Geof 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.
Run PHP file from command Promp.
Please set Environment Variable as per below mention steps.
Now open Command prompt where your source file are available and run command "php test.php"
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
In case some one wants to know how to set up Environment variables
Once you have done that you can run using the command from the start->command line as below
php <path to file location>
In the version 3.2.4 of the XAMPP Control Panel, there is button that can open a command line prompt (red rectangle in the next figure)
After pressing the button, you will see the command prompt window.
From this window you can navigate through the different folders and start the different services available.
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.
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.
A faster option would be to use CMD as administrator. You could type, for example:
setx PATH "%PATH%;C:\xampp\php"
After this, you need to close CMD and reopen. For test type:
php -v
in case you want to directly type e.g. mysql -u root...
in your terminal, all of these answers are ugly :)
xampp_shell.bat
file (it's in the root of xampp folder)C:\xampp\
)xampp.bat
, move it to %SystemRoot%\System32
(probably it's C:\Windows\System32
now in cmd just type xampp
,all of your environment variables are set & you're ready to go...
note: to exit from xampp mode type EXIT;
approach 2: add'em directly to your environment variables: you can read about it here
For windows 11 we have to add both path here, like
C:\xampp81\php C:\xampp\php
and restart / after that run C:\xampp81 xampp-controll.exe
and check php -v in cmd
© 2022 - 2024 — McMap. All rights reserved.
C:\xampp\php\php phpfile.php
– Geof