Add XAMPP's PHP Execution Path to Environment Variables in Windows 10/11

Add XAMPP’s PHP Execution Path to Environment Variables in Windows 10/11

What Are Environment Variables in Windows?

Environment variables are dynamic objects on a computer that contain a value which is made accessible to Windows. Some examples might include your computer name, the location to store temporary files or the location of various executable installed programs. To see a comprehensive list of environment variables in Windows, read our article here.

Environment variables typically follow the structure of %<VARIABLENAME>%. A popular example of this is %APPDATA% which points to C:\Users\{username}\AppData\Roaming. Instead of manually traversing folders to find that location, you can open the Run command (Windows key + R) and type in %APPDATA% to instantly access that same path.

Another popular environment variable in Windows is %PATH% which stores folder paths that are made accessible to the operating system. In this tutorial, we want to look at how to add the executable path for PHP in XAMPP to our %PATH% environment variable. In doing so, we’ll now be able to execute PHP through the Windows command line interface.

Step 01 – Open Windows 10/11 Environment Variables Settings Control Panel

Click on the Windows Start menu and search for “Environment Variables”. Hit Enter on the keyboard or click on the entry to launch the settings control panel.

Windows 10/11 Environment Variables Start Menu Environment Variables Control Panel

Step 02 – Open the Environment Variables Settings Editor Window

Click on the button Environment Variables to launch the editing window.

Windows 10/11 System Properties Dialog Box

Step 03 – Edit the Path Environment Variable

It is important to note here that there are two different types of environment variables: User variables and System variables. The main difference between them is that User variables apply only to the currently logged in user, while System variables apply globally to the computer (and all subsequent users).

In this case, we want to edit the %PATH% environment variable on the System variables. To do so, click first on the Path line, then click on the Edit… button.

If you wish to only apply this for the current user, click first on the Path variable entry under User variables and click on the Edit… button.

For a more in-depth look at environment variables, read our comprehensive list of environment variables article.

Windows 10/11 Environment Variables Control Panel

Step 04 – Add the XAMPP PHP Path

First click on the New button to add a new path entry to the %PATH% environment variable.

Next click on the newly added line inside the Edit environment variable table. If your XAMPP install is located in the default location, you will enter the path value of: C:\xampp\php. Hit Enter on the keyboard and then click OK button to confirm the edit. To finalize the edit, make sure you also click the OK button on the Environment Variables window as well.

Windows 10/11 Edit Environment Variable Dialog Box

Step 05 – Reboot Windows

For the changes to take effect, we’ll need to reboot Windows. A simple shortcut for this is to first minimize all Windows by clicking in the far right of the taskbar or using Windows key + M. Once on the desktop, press ALT + F4 key and choose Reboot.

Windows 11 ALT + F4 Shut Down Windows Dialog Box

Step 06 – Test and Verify Using the Command Prompt to Check PHP Version

To verify that the XAMPP PHP executable path is registered with the system, open a Command Prompt. Next type: php -v in the Command Prompt and you should see a string of values like shown in the screenshot.

Windows 10/11 Command Prompt Checking Installed PHP Version

Now you can utilize PHP command line commands within Windows!

If you found this tutorial helpful or have additional information to share regarding XAMPP, PHP, or Windows, please do so in the comments below and join the discussion!

All screenshots by Michael Smith.

Leave a Comment