Last updated: Apr 4, 2024
Reading time·3 min
The error "'php' is not recognized as an internal or external command, operable program or batch file" occurs for two main reasons:
php
installed on your Windows machine.php
in your system's PATH environment variable.The article consists of 2 subheadings:
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.
where php php -r "echo PHP_BINARY;"
Otherwise, it's easier to just download and install php
following the
instructions.
If you are unsure whether your computer runs 32-bit or 64-bit:
Your system is most likely 64-bit, so you have to download the latest Thread
safe 64-bit Zip
file.
php-8.1.12-Win32...
in my case.php-8.1.12
.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.
php-X.Y.Z
directory to your
system's PATH environment variable.To add the path to php
to your system's PATH environment variable:
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.
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.
where php php -r "echo PHP_BINARY;"
Once the path to your php
directory is added, click on "OK" twice to
confirm.
Close your Command prompt application and then reopen it.
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.
php --version
To solve the error "'php' is not recognized as an internal or external command, operable program or batch file", make sure:
php
installed on your Windows machine.php
in your system's PATH environment variable.You can learn more about the related topics by checking out the following tutorials: