Setting up command-line PHP on Windows
July 28, 2008 – 9:14 am Tags: PHPOn *nix systems you usually have the php executable available in shell, so you can run command-line scripts like unit tests and such, but on Windows this isn’t usually the case. Let’s fix that!
There’s two ways to do this: Temporary and permanent
Temporary
The temporary method will affect only a single command prompt.
Open command prompt (start, run, cmd) and type in the following:
set PATH=%PATH%;C:\path\to\php
Where C:\path\to\php is the folder where your php.exe file is located. After this, you should be able to run PHP in any folder like this:
C:\>php -v
PHP 5.2.5 (cli) (built: Nov 8 2007 23:18:51)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with Zend Extension Manager v1.2.0, Copyright (c) 2003-2007, by Zend Technologies
with Xdebug v2.0.2, Copyright (c) 2002-2007, by Derick Rethans
Your output may vary depending on your PHP version and extensions.
Permanent
The permanent method will affect all command prompts and will persist upon reboots. It can also be set up to affect all users on the system and not only your account.
- Open control panel
- Go to System
- Choose the Properties tab
- Click Environment variables
From this screen you can edit the environment variables of the system. If you only wish to modify them on your user account, click New under your own variables box and type in the following:
Variable name: Path
Variable value: %PATH%;C:\path\to\php
If you want the change to affect all users on the system, choose the Path variable from the system variables box and click Edit.
Append the variable value with:
;C:\path\to\php
Note the ; character. It’s used to separate directories in the var, so be sure it’s present.
Again, C:\path\to\php is where your php.exe is located.
Now you should have the php executable available in command line. Have fun!


13 Responses to “Setting up command-line PHP on Windows”
You might also want to check which php.ini is being used by your webserver and by your client call. They might differ (on linux they almost always do !).
Can give some strange results if extensions aren’t enabled on cli while they are on the web version.
By Harro on Jul 28, 2008
Great. Some times we for get the nitty gritty
By sharma chelluri on May 13, 2009
Clear, just what I was needing!
Kelvin, PR USA
By Kelvin on Jul 14, 2009
This is really very helpful information!
By Harry on Jan 28, 2010
It’s work for me
both way are works!
i’m running on win7 and xampp
thanks
By dht on Dec 18, 2011
Not Working…It says php is not recognized as internal or external command.
By drum on Jan 10, 2013
It’s working!!!!
TY
By drum on Jan 10, 2013
CLI is working perfectly fine now! Thanks!
By Etamina on Jan 31, 2013
thanks… very helpful
By alok on Feb 15, 2013
It is not working in windows command line:(
By İpek on Mar 20, 2013
Its amazing!
After trawling the internet, I have finally found an article that gives absolute beginners like me a step by step guide as to how to do this.
If you go onto forums, and other articles, they start from points that tend to make the whole thing pretty vague.
Thanks codeutopia!
By Peter on Mar 26, 2013