To run PHP from command line in windows you just have to add php executable file path to system variable correctly. If you have installed XAMPP, and want to use command line to run PHP on Windows, here is this helpful article for you.
I have already installed XAMPP in my local pc having windows 7 OS. The most important part is setting path system variable and after learning the steps I described below along with pictures, you will be able to do the same for other OS and programming languages too.
Run PHP from command line in windows and xampp
1. Right click on the Computer icon on your Desktop and choose Properties option.
2. In the System window click on Advanced system settings in the left pane as highlighted below
3. In the System Properties window select Advanced tab from horizontal menu at top and click on Environment Variables button given at the bottom of the window as shown below:
4. In the next window call Environment Variables as shown above, go to the System variable (second grid) and find a variable named Path and click Edit. If the Path variable is not present then click to New.
5. Get the php path where you have installed XAMPP. In my case it’s E:/xampp/php. Add this path to variable value in little dialog box that appeared.
If you are editing then append a semicolon before the path you are adding to separate variables. So it would be ;e:/xampp/php for me.
else in case of new, add Path as variable name and your php path as variable value and click OK.
6. Press OK and close all windows. Now you are ready, let’s test this:
Run PHP from command line
- Open command prompt by typing
cmdin search box under your start menu. - Type
php -vand press Enter - You will get version information as shown:

Furthermore I created a folder called cmdtest under htdocs and a file called index.php inside that folder. I simply wrote <?php echo "Command Working"; ?> as content of this file. Now I executed the following commands to let you be familiar with this:
cd e:/xampp/htdocs (current directory path)
e: (open directory)
cd cmdtest (open the project I’m working)
php index.php (execute a command)

This is all. We just saw how this stuff work? Now you should do working. The system variable is permanently set and you can run PHP from command line in windows and xampp at anytime.
Works wonderfully!
This isn’t working for me
Thanks, I’ve just been looking for info about this topic for a long time and yours
is the greatest I’ve discovered so far.
thanks it helped me
Thanks …. It’s working
Thanks!