Set PHP Environment Variables Windows Xampp Or Wamp
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 post for you.
I have already installed XAMPP in my local pc having windows 7, 8 or 10 OS. The most important part is setting path system variable and after learning the steps I described below along with step and image, you will be able to do the same for other OS and programming languages too.
Step 1 Setting environment variables in Windows
Setting environment variables in Windows is pretty hidden in several layers of settings dialogs. Just like most things in Windows, we will set environment variables using a graphical user interface. To open the respective interface you first have to open the Windows Run prompt . Do so by pressing the Windows + R key on your keyboard at the same time. Type sysdm.cpl into the input field and hit Enter or press Ok.According to image shown below:
Step 2 System Properties window
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 According to image shown below:
Step 3 Environment Variables as shown
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 on Edit button . If the Path variable is not present then click to New button. According to image shown below:
The window has two different sections. One is the list of environment variables that are specific to your user. This means they aren’t available to the other users. The other section contains the system-wide variables that are shared across all users.
Step 4 Edit System Varisble
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. According to image shown below:
Step 5 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: