The error message “PHP is not recognized as an internal or external command, operable program or batch file” typically occurs when you try to run a PHP script or command in your command prompt or terminal, but the system cannot find the PHP executable in the system’s PATH.
php is not recognized as an internal or external command, operable program, or batch file; Through this tutorial, you will learn how to set or add PHP environment variables in Windows xampp to fix php is not recognized as an internal or external command, operable program or batch file.
PHP is not recognized as an internal or external command
Steps to set php environment variables windows xampp to fix php is not recognized as an internal or external command, operable program, or batch file:
- Step 1 – Open Windows Environment Setting
- Step 2 – Edit Environment Setting
- Step 3 – Edit System Environment Variable Path
- Step 4 – Add PHP Path
- Step 5 – Restart Windows 11|10
- Step 6 – Open the Command Prompt and Check the PHP Version
Step 1 – Open Windows 11/10 Environment Setting
First of all, visit your system’s bottom search bar and search Environment Variables; as shown below picture:
Step 2 – Environment Setting
Then Click on the environment variable setting; as shown below picture:
Step 3 – Edit System Environment Variable Path
Edit system environment variable path; as shown below picture:
Step 4 – Add PHP Path
Add/set PHP xampp path in environment setting; as shown below picture:
Note that; we have installed xampp in the D directory.
If you are using linux or mac system, to add/set PHP xampp path in environment setting:
- Open a terminal window.
- Edit your shell configuration file (e.g.,
~/.bashrc
,~/.zshrc
, or~/.profile
) using a text editor (e.g.,nano
,vim
, orgedit
). - Add the following line to the file, replacing
/path/to/php
with the actual path where PHP is installed:- export PATH=”/path/to/php:$PATH”
- Save the file and exit the text editor.
- Run
source ~/.bashrc
orsource ~/.zshrc
(or the appropriate file for your shell) to apply the changes to your current terminal session.
Step 5 – Restart Windows 11|10
Restart your Windows 11|10 system.
Step 6 – Open the Command Prompt and Check the PHP Version
After adding PHP to your PATH, open a new terminal or cmd window and type php -v
(on Windows) or php --version
(on Linux/macOS) to check if PHP is recognized as a command. You should see the PHP version information if PHP is correctly installed and configured.
php -v