php error : php command not found - php

My system is win7. I have installed XAMPP on the system successfully.Besides, I have set the environment variables:
PHP_HOME=C:\xampp\php
Path=%PHP_HOME%
But when i run php code in git bash ,it appears the error:"sh.exe:php:command not found"
How can i solve the problem?

In my case I can solved my problem in this way ...
Go to PHP directory in the XAMPP folder and run the code in this way with the XAMPP server:
$ Php /c/xampp/htdocs/cupon/bin/vendors install

As far as i was trying to execute MSVC compiler from within Java, i got the idea of all that Win7: the shell you are running something has different environment variables that you think you've set.
I recommend you to insall WAMP server - it is totally compatible with Windows while XAMPP seems to be a bit hard way to start with.
And one more hint: try running php / sh from the bin/ PHP directory.

If you're using Windows and getting the "php: command not found" error, it means that the PHP executable is not in your system's PATH environment variable. Here are the steps to fix it:
Find the location of your PHP installation. By default, PHP is installed in the "C:\php" directory. If you've installed PHP in a different location, note down that path.
Add the PHP directory to the system's PATH environment variable:
Open the Start menu and search for "Environment Variables."
Click on "Edit the system environment variables."
Click on the "Environment Variables" button at the bottom of the window.
Under "System Variables," scroll down and find the "Path" variable. Click "Edit."
Click "New" and enter the path to your PHP directory (e.g., "C:\php").
Click "OK" to close all the windows.
Close and reopen your terminal or command prompt to apply the changes.
Verify that PHP is working by running the command "php -v" in your terminal or command prompt. You should see the version of PHP installed on your system.
If PHP is still not working after following these steps, you may need to reinstall PHP or check that the PHP executable file is in the correct directory.

Related

I have php installed yet I get 'php' is not recognized as an internal or external command, operable program or batch file [duplicate]

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.
Add C:\xampp\php to your PATH environment variable.(My Computer->properties -> Advanced system setting-> Environment Variables->path (click on edit))
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.
You need to Go to My Computer->properties -> Advanced system setting
Now click on Environment Variables..
Add ;C:\xampp\php in path variable value
Now restart command prompt DONE!
Note: Make sure you run CMD via run as administrator
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.
Set "C:\xampp\php" in your PATH Environment Variable. Then restart CMD prompt.
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.
Is your path correctly configured?
In Windows, you can do that as described here:
http://www.computerhope.com/issues/ch000549.htm
For Laragon:
First, download your PHP from [https://windows.php.net/download/]
then unzip your file -> copy folder -> paste this direction:
C:\laragon\bin\php`Your folder`
search from windows
Edit the system environment variables
and then open it.
Click Environment variables...
Click path and Edit
Click New and add the php.exe path
like:
C:\laragon\bin\php`Your folder`
and then press OK for all steps.
restart laragon and vscode
and our problem is already solved.
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
I also got the following error when I run a command with PHP, I did the solution like that:
From the desktop, right-click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
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.
In the Edit System Variable window, Add C:\xampp\php to your PATH Environment Variable.
Very important note: restart command prompt
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)
In latest Xampp 8.1.2
PHP path is changed to this below: Set it in your PATH variable.
C:\xampp\php\windowsXamppPhp
Don't forget to restart the PowerShell and run as Administrator.
I faced this issue even with a properly set up windows environment variable. I just needed to close and restart the terminal to solve it.
The previous answers about adding the path to the Env Var are correct, but my case was different.
I needed to downgrade my PHP version to 5 in order to update an old application.
I was using the following combination: MAMP, PhpStorm, the Environment Variable Path was set properly to the MAMP PHP version that I was using
The error was showing in PhpStorm's Terminal
The error was due to the php.ini file using # in the comment
After I replaced "#" by ";" I restarted PhpStorm and recognized the PHP version and the command "php -v" worked again
I have to face the same problem which I solved by adding the path of XAMP/WAMP to PATH environment variable.
Follow these steps:
Go to System Properties
Go to Advanced
Go to Environmental Variables
Edit the Path environment variable
Add the installation path of xammp/wamp like in my case the path is E:\xammp\php
Click on Ok
Restart command prompt (cmd)
Check the version of PHP by running php --version.
Laragon users
you will find your PHP folder in the bin folder of laragon. goto your desired PHP version folder and copy the location. for me it was:
C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64
Add that location on your system PATH:
After that, you need to restart your cmd or terminal.
In my case the problem was in the path, I was giving the path to the php.exe and that's wrong I have to write the path of the root folder...
I restarted CMD program it solves my problem

'php' is not recognized as an internal or external command in terminal

I installed php5 on monday and it was working with no problems and it's been working up until today when I tried to do a "php artisan migrate" command in the terminal and it said it wasn't recognized, I have the php5 folder saved in "C:\" and hasn't been moved since installation.
Probably You should append directory path of your php.exe to windows PATH environment variable. But be careful by changing this variables. Some information can be found here: http://www.itechtalk.com/thread3595.html or just use Google for more examples.
Kindly try php -v from the command prompt. If you get something like PHP 5.6.10 as output, then your php exists in your path.
In case your PATH is not set, you can use the SET command to set your PHP for that particular instance. Or you can go to My Computer --> Properties --> Advanced --> Environment Variables and append your php directory to the PATH variable.
Thanks!
I reinstalled wamp and in doing so moved my old wamp folder to the desktop forgetting that I had used the wamp php file as my environment path. Ty for all your suggestions

PHP is not recognized as an internal or external command in command prompt

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.
Add C:\xampp\php to your PATH environment variable.(My Computer->properties -> Advanced system setting-> Environment Variables->path (click on edit))
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.
You need to Go to My Computer->properties -> Advanced system setting
Now click on Environment Variables..
Add ;C:\xampp\php in path variable value
Now restart command prompt DONE!
Note: Make sure you run CMD via run as administrator
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.
Set "C:\xampp\php" in your PATH Environment Variable. Then restart CMD prompt.
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.
Is your path correctly configured?
In Windows, you can do that as described here:
http://www.computerhope.com/issues/ch000549.htm
For Laragon:
First, download your PHP from [https://windows.php.net/download/]
then unzip your file -> copy folder -> paste this direction:
C:\laragon\bin\php`Your folder`
search from windows
Edit the system environment variables
and then open it.
Click Environment variables...
Click path and Edit
Click New and add the php.exe path
like:
C:\laragon\bin\php`Your folder`
and then press OK for all steps.
restart laragon and vscode
and our problem is already solved.
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
I also got the following error when I run a command with PHP, I did the solution like that:
From the desktop, right-click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
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.
In the Edit System Variable window, Add C:\xampp\php to your PATH Environment Variable.
Very important note: restart command prompt
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)
In latest Xampp 8.1.2
PHP path is changed to this below: Set it in your PATH variable.
C:\xampp\php\windowsXamppPhp
Don't forget to restart the PowerShell and run as Administrator.
I faced this issue even with a properly set up windows environment variable. I just needed to close and restart the terminal to solve it.
The previous answers about adding the path to the Env Var are correct, but my case was different.
I needed to downgrade my PHP version to 5 in order to update an old application.
I was using the following combination: MAMP, PhpStorm, the Environment Variable Path was set properly to the MAMP PHP version that I was using
The error was showing in PhpStorm's Terminal
The error was due to the php.ini file using # in the comment
After I replaced "#" by ";" I restarted PhpStorm and recognized the PHP version and the command "php -v" worked again
I have to face the same problem which I solved by adding the path of XAMP/WAMP to PATH environment variable.
Follow these steps:
Go to System Properties
Go to Advanced
Go to Environmental Variables
Edit the Path environment variable
Add the installation path of xammp/wamp like in my case the path is E:\xammp\php
Click on Ok
Restart command prompt (cmd)
Check the version of PHP by running php --version.
Laragon users
you will find your PHP folder in the bin folder of laragon. goto your desired PHP version folder and copy the location. for me it was:
C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64
Add that location on your system PATH:
After that, you need to restart your cmd or terminal.
In my case the problem was in the path, I was giving the path to the php.exe and that's wrong I have to write the path of the root folder...
I restarted CMD program it solves my problem

Command 'php' not recognized but it is registered in Windows PATH

I have "C:\Ampps\php" setup in the PATH string on my Windows server but when I type 'php' on the PHPStorm terminal I'm always given 'php' is not recognized as an internal or external command, operable program or batch file.
Is this a bug with PHPStorm 7.1.3? It works from the command line if I open a new Command Prompt window externally.
For any new readers facing such problem in PhpStrom just set path directly from PhpStrom terminal
set path=%path%;c:/xammps/PHP
Not recommended to use PHP from xammps or other such programs since it will be your working PHP directory and if it gets deleted then you have to perform another task to handle it or some errors might pop up in windows just install a fresh version of PHP lots of tutorials are out there for Windows.
But nevertheless to use PHP in PhpStrom Terminal from xammps just run that command it will set the path that PhpStrom can find.
I had the same problem. I have "C:\__OPENSERVER__\modules\php\PHP-7.2-x64" setup in the PATH.
To solve it I added in PhpStrom terminal and executed:
set path=%path%;C:\__OPENSERVER__\modules\php\PHP-7.2-x64
open setting in file menu
find tools tab in this window
click on terminal
in project setting click on environment variable
add php path (for example "C:/xampp/php") to this and save
restart phpstorm

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

‘php.exe’ is not recognized as an internal or external command,
operable program or batch file.
Why does that error occur even though I've added PHP to my environment variables?
My environment variable PATH is shown below:
C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Program
Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\PC
...............
Files\QTSystem\;A:\xampp\php\php.exe
I'm using Windows 7.
A:\xampp\php\php.exe
The PATH environment variable must contain paths only, not file names.
Make that
A:\xampp\php
it is very easy to do
You need to also add php.exe
Adding this path:
windows key + pause
click on Advance system settings
click Environment Variable
System variables part -> Path -> Edit and the add
C:\wamp\bin\php\php5.3.8;
close you cmd prompt if its open
It's Done!
I think you need to change it to A:\xampp\php\ and just leave it there, then it will search the directory for the file, also: have you tried calling just php instead of php.exe and check that the directory is correct.
View above screen shot for setup enviroment variable in window 7
Note:- After setup enviroment variable please restart you computer then its will work fine
Shouldn't the last part be: C:\xampp\php\ ? Unless you remapped your drives, A is the floppy disk. :)
Also, you need to specify the folder, not the exe file itself.
My case am Using Bitnami Ruby Stack apache Web server ,
Pressed Windows key + Pause/Break Button
Clicked advanced system settings
Click Environment Variables
Under System variables > edit PATH variable by adding C:\Bitnami\rubystack-1.9.3-24\php
Click Ok to close the Environment Variable window
Close your command prompt if open
*(Proceed to 7. to confirm if php is installed)
Press Windows Key + R button to open your cmd
Type php -v to view your php version
Set PHP as environment variable from System as below to run it from CMD
1)Windows key + Pause
2)Click on Advanced system settings
3)Now click on Environment Variables.. button
4)In system variable section search for Path and edit it as D:\wamp\bin\php\php5.3.13;(If one needs to append it to some already exits value then start path with;)
5)Now open CMD and run command PHP from any path where you don’t have PHP installed , in my case it’s C drive.
6)We can check above set Path from CMD using Path command also.
If you have installed WAMP server, then your path can vary. For example, I installed WAMP and the path to my php.exe turned out to be:
C:\wamp\bin\php\php5.5.12\php.exe
To make it work, I entered the following path in the PATH variable of the System Variables:
C:\wamp\bin\php\php5.5.12
Once done, I restarted command prompt and everything worked fine.
So the path can vary depending upon how you installed PHP. If you would like to install WAMP server and have it install other essential packages like PHPMyAdmin, etc. you may do so from: wampserver.com
In my case, environment path is C:\ProgramData\Drush\;C:\Program Files (x86)\Drush\Php; and it works for me.
If I simply add C:\xampp\php\ dint work for me.
I hope if someone facing this issue can try this suggestion.
This happened to me and I found why.
Xampp can't run properly depending on your UAC settings.
Try to do this:
Log in as administrator (running cmd.exe as administrator isn't enough)
Execute cmd.exe or equivalent
type php -version

Categories