Set PHP Environment Variables Windows Xampp Or Wamp

By : PHPErrorCode July 17, 2017 1032 Views php

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:

windows run promt

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:

system property

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:

Environment variables

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

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. According to image shown below:

pHP Path insert

Step 5 Run PHP from command line

  1. Open command prompt by typing cmd in search box under your start menu.
  2. Type  php -v  and press Enter
  3. You will get version information as shown:

CMD promt

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 xampp or wamp at anytime.