Today I will explain how to add your PHP runtime directory to your Windows 10 Please note that you must reopen your command prompt windows [if you had any open prior to the update]. Command prompt loads the Note that you are not limited to PHP, this can be any directory containing any program - ex.: Copy shortcut: And voilà! If it displays PHP help then it worked!PATH
environment variable. This will give you global access to php.exe
from any command prompt.PATH
environment variable when it is first open.Target audience
npm
ctrl+C
Paste shortcut: ctrl+V
C:\MAMP\bin\php\php5.6.21
[the PHP version may vary].How to test if it worked out
php -?
Comments
I am trying to learn how to access PHP scripts from the command line [CLI]
Below is an image from my attempt, please help. I am running Windows 7
asked Sep 5, 2011 at 11:41
JasonDavisJasonDavis
47.2k97 gold badges305 silver badges525 bronze badges
You need to add your PHP
installation directory to the %PATH%
environment variable, or work from the PHP installation directory.
To add it to path [The best approach - Edited for Windows 7]:
- Right-click on a
My Computer
icon - Click
Properties
- Click
Advanced system settings
from the left nav - Click
Advanced
tab - Click
Environment Variables
button - In the
System Variables
section, selectPath
[case-insensitive] and clickEdit
button - Add a semi-colon [
;
] to the end of the string, then add the full file system path of your PHP installation [e.g.C:\Program Files\PHP
] - Keep clicking
OK
etc until all dialog boxes have disappeared - Close your command prompt and open it again
- Sorted
Alternatively, you can run cd
before you try and run you command, or call your script like
answered Sep 5, 2011 at 11:44
DaveRandomDaveRandom
86.8k11 gold badges149 silver badges173 bronze badges
5
For temporary use, try this: [benefit for use npm
or composer
]
> SET PATH=c:\wamp\bin\php\php5.3.29\;%PATH%
For test use this:
> echo %PATH%
c:\wamp\bin\php\php5.3.29\;c:\anothers\;
Now you can access to PHP
command:
> php -v
PHP 5.3.29 [cli]
answered May 17, 2018 at 2:29
Nabi K.A.Z.Nabi K.A.Z.
8,7466 gold badges53 silver badges71 bronze badges
1
Easy Way: Run CMD then type
C:\wamp\bin\php\php5.4.3\php.exe -f "C:\wamp\www\timenow.php"
Change the last part for a different script, and make sure you have the same version php folder as I do. [php5.4.3]
answered Feb 3, 2014 at 16:02
1
On 2020 and with Windows 10 there's an easier way to achieve this.
1- Download composer at //getcomposer.org/Composer-Setup.exe
2- Install it as you install any program on windows and [important] when it asks you the path to PHP, browse thru the correct path [for example: c:/wamp/bin/php.exe]
FINNISHED! Close the cmd and reopen and you can run PHP on your command line and also COMPOSER [composer is actually very needed if you use PHP]
answered Jul 4, 2020 at 21:24
gtamborerogtamborero
2,47923 silver badges23 bronze badges
you can run cd before you try and run you command, or call your script like
answered Dec 16, 2021 at 4:18