'php' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
3 min

banner

# 'php' is not recognized as an internal or external command

The error "'php' is not recognized as an internal or external command, operable program or batch file" occurs for two main reasons:

  1. Not having php installed on your Windows machine.
  2. Not having the path to php in your system's PATH environment variable.

php is not recognized as internal or external command

The article consists of 2 subheadings:

  • Download and install PHP on your Windows machine
  • Add the path to PHP to your system's PATH environment variable
If you already have php installed and know where the php folder that contains the php.exe file is located, you can scroll down to the next subheading.

You can use the following 2 commands to try to find the path to your php.exe file, but they probably won't work if you don't have php configured properly.

cmd
where php php -r "echo PHP_BINARY;"

find php install folder

Otherwise, it's easier to just download and install php following the instructions.

# Download and install PHP on your Windows machine

  1. Visit the php downloads page and click on "Windows downloads".

php click windows downloads

If you are unsure whether your computer runs 32-bit or 64-bit:

  • Click on the Start button, then click Settings > System > About.
  • Look at the value of "System type".

windows check if 32 64 bit

Your system is most likely 64-bit, so you have to download the latest Thread safe 64-bit Zip file.

download-zip-latest-version

  1. Open your Downloads directory, right-click on the zip file and click "Extract All".

extract zip file

  1. The folder containing the output is called php-8.1.12-Win32... in my case.
To make it a bit more readable, I'll rename it to php-8.1.12.
  1. The next step is to copy the folder to C:\Program Files. Note that this will require administrative permissions.

If you don't have elevated permissions, you can copy the folder to another location.

copy to program files

  1. The next step is to add the path to the php-X.Y.Z directory to your system's PATH environment variable.

# Add the path to PHP to your system's PATH environment variable

To add the path to php to your system's PATH environment variable:

  1. Click on the Search bar and type "environment variables".
  2. Click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. In the "System variables" section, select the "Path" variable and click "Edit".

select path and click edit

  1. Click on "New" and then click "Browse".

click new browse

  1. Either copy and paste the directory in which you pasted the php-X.Y.Z folder or navigate to it using the Browse button.

I used the C:\Program Files directory, so in my case the path is C:\Program Files\php-8.1.12.

Note that your php version will likely be different than the one used in the examples.

environment-variable-added

You can also use the following 2 commands to try to find the path to your php.exe file, but they probably won't work if you don't have php configured properly.

cmd
where php php -r "echo PHP_BINARY;"

find php install folder

  1. Once the path to your php directory is added, click on "OK" twice to confirm.

  2. Close your Command prompt application and then reopen it.

Note that you must restart your Command prompt shell for the changes to take effect.

You might also have to restart your PC, but that's not always necessary.

Assuming you opened a new CMD shell, use the php --version command to verify that php is installed successfully.

cmd
php --version

issue php command

# Conclusion

To solve the error "'php' is not recognized as an internal or external command, operable program or batch file", make sure:

  1. You have php installed on your Windows machine.
  2. You have the path to php in your system's PATH environment variable.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.