[Fixed] PHP is not recognized as an internal or external command

[Fixed] PHP is not recognized as an internal or external command

The PHP is not recognized as an internal or external command, operable program or batch file error typically occurs when the PHP executable path cannot be added in the system’s PATH environment variable. In this tutorial, we will show you two approaches on how to fix this error.

Here are two possible solutions that you can follow to fix this error.

  • Solution 1: Set PHP path to system environment variable
  • Solution 2: Uninstall and Reinstall xampp PHP

Solution 1: Set PHP path to system environment variable

If you already have PHP installed in your system and you get the error like PHP is not recognized as an internal or external command, operable program or batch file, then Windows XAMPP

Then, you can easily fix this by adding the php executable path to the system’s PATH environment variable. Here are steps to fix this:

  • 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, or gedit).
  • 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 or source ~/.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

Solution 2: Uninstall and Reinstall xampp PHP

Still get the same error after using first Solution. So, you need to uninstall xampp php from your system and re-install xampp php.

Recommended Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *