____ is not recognized as an internal or external command

Advertisement

We know that PHP is a server-side scripting language. But, We can execute the PHP script through the command link too.

But, Most of the time we face an issue:

____ is not recognized as an internal or external command 1
____ is not recognized as an internal or external command 7

This is because the environment path for the php.exe file does not exist. To make it work you need to set the environment path into the system setting.

Table of Content

Add Environment Path Add Environment Path

Step 1: Click on the Start menu from Windows Operating System and search for Environment Variables and then click on Environment Variables

____ is not recognized as an internal or external command 2
____ is not recognized as an internal or external command 8

Step 2: Edit the System variables or User Variables

  • System variables – If we add a path in system variables then other system users also use the PHP through the command line.
  • User variables – If we set the path for the current user then only the current user can execute the PHP through the command line.
____ is not recognized as an internal or external command 3
____ is not recognized as an internal or external command 9

Step 3: Add the PHP directory location where the PHP is installed. In XAMPP we can find the PHP location at:

c:\xampp\php

So, Click on New, add the path, and click on Ok.

____ is not recognized as an internal or external command 4
____ is not recognized as an internal or external command 10

Top ↑

Testing Testing

To test the PHP is available with the command line.

  • Open Terminal (CMD)
  • Type php -v

You can see something similar on screen.

____ is not recognized as an internal or external command 5
____ is not recognized as an internal or external command 11

Top ↑

Example Example

Now, Let’s see how to execute the PHP script through the command line with the simple example.

Note: I assume that you have a localhost server XAMPP, MAMP, WAMP, VVV, Local By Flywheel, or something else.

Step 1: Create a file test.php in c:\xampp\htdocs\examples

Step 2: Copy and paste the below code into the file test.php

<?php
echo 'Hello World';

Step 3: Open a terminal or CMD (Command Prompt) and navigate to the examples directory.

cd c:\xampp\htdocs\examples

Step 4: Execute command

php test.php

You can see Hello World on the terminal screen like:

____ is not recognized as an internal or external command 6
Hello World Program Output

One thought on “____ is not recognized as an internal or external command

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: