To run PHP from command line in windows you just have to add php executable file path to system variable correctly.
Run PHP from command line in windows and wamp
1. Right click on the Computer icon on your Desktop and choose Propertiesoption.
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 WAMP. In my case it’s C:\wamp64\bin\php\php5.6.25. Add this path to variable value in little dialog box that appeared.
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 cmd in search box under your start menu.
- Type php -v and press Enter
- You will get version information as shown:
Furthermore I created a folder called vineet under D: drive and a file called test.php inside that folder. I simply wrote <?php echo “Vineet Kumar Saini”; ?>
The system variable is permanently set and you can run PHP from command line in windows and wamp at anytime.