When calling the php
command from the Windows command prompt, you may see a message saying that ‘php’ is not recognized as an internal or external command, operable program or batch file.
Here’s an example of the issue:
This issue appears when Windows has no idea what you mean with the php
command.
To solve ‘php’ is not recognized as an internal or external command issue, you need to add the folder containing your PHP program to the Windows environment variable.
You can do so in five steps as shown below:
This tutorial uses Windows 11, but the solution will work on all Windows versions (XP, Vista, 7, 8, and 10).
Step #1: Find your PHP folder location
You first need to find the location of PHP that you installed on your Windows machine.
There are several ways you can get PHP installed: You can download the latest PHP version from windows.php.net, or you can download bundled software like XAMPP, WAMP, or MAMP.
No matter where you got PHP from, you need to find the php/
folder on your machine.
For example, here’s an example of php/
folder from XAMPP:
Step #2: Copy PHP folder path
Once you find the php/
folder, click on the visible URL bar, then click copy:
Next, you need to put this path on Windows environment variable.
Step #3: Open Windows environment variable menu
Open the Start menu in your machine and type “var” or “variables” in the search bar.
You should see Windows shows Edit the system environment variables menu on the search result as shown below:
Click on that menu and you will be taken into System Properties menu.
Locate the environment variables menu as shown below:
Click on the menu, and you’ll see the Environment Variables for the current User and the System.
Step #4: Add PHP to your Path variable
You need to edit the Path
variable in either the User or System variables as shown below:
The User path only applies for the current user, while the System path is active for all users.
If you have only one user who will use PHP, you can put the path in User variables.
Click on the Path
variable, then click Edit…
You need to add the php/
folder path to the environment as shown below:
After you add the php/
path, click OK.
Step #5: Restart Command Prompt and run php command again
You need to restart your Command Prompt once before you can use the php command.
Close and then open your Command Prompt again. Run the php -v
command, and you should see the PHP version as follows:
This means that Windows recognized the php
path you put in the environment variables.
And that’s how you solve the issue ‘php’ is not recognized as an internal or external command, operable program or batch file.
Optional: Use PHP from another source
The same method also works when you have PHP downloaded from windows.php.net.
For example, I’ve downloaded the latest PHP v8.1.10 from windows.php.net and extracted it to my Downloads/
folder.
To make Windows use this version of PHP, I only need to change the Path environment variables as shown below:
Once I clicked OK, I restarted the Command Prompt and ran the php -v
command again.
This time, the PHP version is different than the one from XAMPP:
Now you’ve learned how to solve ‘php’ is not recognized as an internal or external command, operable program or batch file issue on your Windows machine. Nice work!