123

I got the following error when I run a command with php

C:\xampp\htdocs>php
'php' is not recognized as an internal or external command,
operable program or batch file.

I don't get any error when I run the command with php in following path:

C:\xampp\php>php  //do not got error here

Why I get this error?

'php' is not recognized as an internal or external command, operable program or batch file.

Paolo Forgia
  • 5,804
  • 7
  • 39
  • 55
Sadikhasan
  • 17,212
  • 19
  • 72
  • 111

10 Answers10

191

Add C:\xampp\php to your PATH environment variable.(My Computer->properties -> Advanced system setting-> Environment Variables->edit path)

Then close your command prompt and restart again.

Note: It's very important to close your command prompt and restart again otherwise changes will not be reflected.

Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
123

You need to Go to My Computer->properties -> Advanced system setting

Now click on Environment Variables..

enter image description here

Add ;C:\xampp\php in path variable value

enter image description here

Now restart command prompt DONE!

Note: Make sure you run CMD via run as administrator

Nigel Ren
  • 51,875
  • 11
  • 34
  • 49
Prince Patel
  • 2,442
  • 1
  • 19
  • 26
16

You just need to a add the path of your PHP file. In case you are using wamp or have not installed it on the C drive.

The picture shows how to find the path

Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
Progga Ilma
  • 400
  • 2
  • 6
11

Set "C:\xampp\php" in your PATH Environment Variable. Then restart CMD prompt.

Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
Vikas
  • 237
  • 2
  • 10
6

Is your path correctly configured?

In Windows, you can do that as described here:

http://www.computerhope.com/issues/ch000549.htm

Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
5

You need to add C:\xampp\php to your PATH Environment Variable, Only after then you would be able to execute php command line from outside php_home.

Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
Raja
  • 811
  • 9
  • 22
3

I also got the following error when I run a command with PHP, I did the solution like that:

  1. From the desktop, right-click the Computer icon.
  2. Choose Properties from the context menu.
  3. Click the Advanced system settings link.
  4. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  5. In the Edit System Variable window, Add C:\xampp\php to your PATH Environment Variable.

Very important note: restart command prompt

Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
Udhav Sarvaiya
  • 6,939
  • 10
  • 42
  • 51
  • This error occurs when you try to use by command. With the given solution, your environment variable path will be corrected, But if you do not close the command prompt after changing the path, then old path will work only. if you have not restarted your command prompt then the changes will not be reflected. After changing the environment variable path, close the command prompt (If the command prompt was open before making changes) and reuse the command prompt for further use. – Udhav Sarvaiya Oct 29 '18 at 05:44
1

enter image description here enter image description here

Here what I DO on MY PC I install all software that i usually used in G: partian not C: if my operating system is fall (win 10) , Do not need to reinstall them again and lost time , Then How windows work it update PATH automatic if you install any new programe or pice of softwore ,

SO

I must update PATH like these HERE! all my software i usually used

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;G:\HashiCorp\Vagrant\bin;G:\xampp\php;G:\xampp\mysql\bin;G:\Program Files (x86)\heroku\bin;G:\Program Files (x86)\Git\bin;G:\Program Files (x86)\composer;G:\Program Files (x86)\nodejs;G:\Program Files (x86)\Sublime Text 3;G:\Program Files (x86)\Microsoft VS Code\bin;G:\Program Files (x86)\cygwin64\bin

enter image description here

Abubakr Elghazawy
  • 707
  • 12
  • 16
1

Extra info:

If you are using PhpStorm as IDE, after updating the path variable you need to restart PhpStorm so that it takes effect.

Restarting terminal window was not enough for me. (PhpStorm 2020.3.2)

Adem Tepe
  • 302
  • 3
  • 10
0
I Have to face the same problem which I solve check my answer.
Follow these steps:
1)System Properties
2)Advanced
3)Environmental Variables
4)Path 
5)add the installation path of xammp/wamp like in my case the path is(E:\xammp\php)
5)Ok
6)Restart cmd
7)check the version of PHP(PHP --version)

enter image description here

Anwar Zahid
  • 146
  • 1
  • 10