PHP and composer command don't work without admin CMD - php

I have problem with my PHP and composer. I have set environment variables:
But whenever I call php or composer I get an error:
It's weird, because when I start cmd as an admin it works. But I want it to work always, because its much easier to write cmd to navigation path which opens the command line in exact path I use and don't need to write cd commands every time I need something.

Have you tried installing composer with the Windows GUI? If I remember correctly, it sets up your path variables itself.
https://getcomposer.org/doc/00-intro.md#installation-windows
You could try adding the same path to your user path variables too, in the first box. I guess you're restarting your CMD window?

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

'mysqldump' is not recognized as an internal or external command

currently im trying to make backup and restore mysql database in my laravel project. I am using this laravel package https://github.com/backup-manager/laravel for backup package. i already follow the intructions, but when i am trying to backup my local database through command line (php artisan db:backup) in the last question, i got this message.
Dumping database and uploading...
[BackupManager\ShellProcessing\ShellProcessFailed]
'mysqldump' is not recognized as an internal or external command,
operable program or batch file.
I already googling it, and already put C:\xampp\mysql\bin to my windows env variables paths, but i still having this issue. if anybody know how to fix this, please tell me, i really appreciate it.
Laravel 5.1.x
It is because mysqldump.exe is not found in that location, the right path is given bellow
Open Command Prompt and type this
cd C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin
Press Enter
then type
mysqldump.exe
or,
Directly open this directory "C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin" and Press LEFT SHIFT KEY from keyboard and RIGHT CLICK on the Directory Window.
then type
mysqldump.exe
It will work 100% correctly
If you are using Xamp then:
Open your Xamp folder
Go to \mysql\bin find the mysqldump.exe
Go to your environment variables under System variable click on 'New'.
As 'variable name' put 'mysqldump'(without the quotes) and as 'variable value' put the path to your xamp\mysql\bin\mysqldump.exe this will make 'mysqldump' available as a global system alias.
Reminder: Make sure to restart your command-line interface.
It happened with me and I solved it by adding the following line at the top of the .bat file.
cd "C:\xampp\mysql\bin"
Please add C:\xampp\mysql\bin to this path at your user variables and system variables. If you are using a wamp server, add C:\wamp64\bin\mysql\mysql8.0.27\bin this path at your user and system variables.
Note: MySQL version path will change as per your installation.
On my side, I was using PowerShell and I had the same error message.
I had to go inside the directory of MySql. Mine was located in:
C:\Program Files\MySQL\MySQL Server 5.7\bin
Then I had to make sure that I had mysqldump.exe in the bin folder.
And then run this command:
./mysqldump.exe -u root -p yordbName > C:\MySqlDump\sakila.sql
It is late, but I will answer to this question for other people who have the same issue.
You need to add the mysqldump.exe runtime file path to your Windows environment variable. I am using Wamp, the path look like this "C:\wamp64\bin\mysql\mysqlx.x.xx\bin"
Close your command-line interface and try again, It should work.
I am using Xamp and the following step is working:
Copy the path "C:\xampp\mysql\bin"
Go to your environment variables under System variable click on 'Path' and add "New".
Put the path there then click ok.
Restart your command-line interface.

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

ERROR: "/app/etc/" must exist for proper tool work magento 1.9

I am trying to install the newly release security patch for magento 1.9. I am working on window system.
and I am getting the following error.
D:\xampp\htdocs\magento>sh PATCH_SUPEE-1533_EE_1.13.x_v1-2015-02-10-08-18-32.sh
ERROR: "/app/etc/" must exist for proper tool work.
I am running command by CMD and SH is working fine too
I tried with Git too. but getting same error
Not working on Linux too
can anyone tell me what is the exact issue and how it could be fixed.
Thanks
Able to make it works on windows machine as well for PATCH_SUPEE-5344_CE_1.8.0.0_v1-2015-02-10-08-10-38.sh.
Problem was: CURRENT_DIR=$PWD_BIN/ (line 60) and the value of $PWD_BIN is defined in same file PWD_BIN=which pwd (line 35) as which doesn't wok on windows so we will need to replace this value.
Open bash
Your current directory should be the root of magento.
Run command 'pwd'
It will give the out path of your current directory: Check screenshot
Copy this path and edit file, on line 67 replace:
CURRENT_DIR=$PWD_BIN/ to CURRENT_DIR=/d/xampp/htdocs/magento/
Run patch with same commnd sh PATCH_SUPEE-5344_CE_1.8.0.0_v1-2015-02-10-08-10-38.sh
Note: Make sure you replace '/d/xampp/htdocs/magento/' with your directory root.
and it will work like a charm!!
Getting rid of the forward slash at the end of line 67 seems to work better for me.
Before: CURRENT_DIR='$PWD_BIN'/
After: CURRENT_DIR='$PWD_BIN'
In SSH, you can change the directory by entering the command, cd /path/to/magento/location/ and then you'll be able to run the bash command to install the patch. If you're not aware of the path, you can run the command, pwd which tells you your current directory. If you're not in the right location, it's looking for app/etc in the wrong location (likely your root folder). So try changing your current directory to the Magento directory and then the error should go away.
I was having the same problem and previous answers didn't work for my situation. The way I was able to fix the issue was to change the directory and then run the bash in SSH.
Run the command, pwd. This will give you your current path.
Change the directory to your Magento directory by running the command, cd /path/to/your/magento/directory/. This should be the path from your current location to the Magento destination.
Now run the bash patch update... bash PATCH_SUPEE-1533_EE_1.13.x_v1-2015-02-10-08-18-32.sh. Now that you're in the right location, the patch update should run smooth!
This error occurs if you are in your root directory for example and not in your Magento root. Go to your Magento folder and run you command again.
This error happens if the folder is not found or don't have enough permissions.
Use the git bash under windows that should work. With a normal CMD it's not working because there are some difference in the path and the normal CMD can't find that path from your patch file.
I have tried above change. But, I need to do some change in that to make it working
I changed it CURRENT_DIR=$PWD_BIN to CURRENT_DIR="/D/wamp/www/magento/"
It was not working without " (quotes)
Hope this will help you.

How to tell Git I'm upgrading php?

I've just upgraded PHP to the latest version. When I get back to Git, to my command shell, if I execute any PHP function, then I get this error :
sh.exe": php: command not found
I know I have to tell git bash where my new PHP path is, but I don't know how to do so and I can't find anything on Google about that.
EDIT :
I made a confusion you're right : I meant Git BASH by git. Thanks :)
SO here is the function I tried to call when I was dealing with symfony in the root foler of my app :
php app/console dump-sql
then Git BASH sent me the error above.
If you are windows, then following up on halfer's comment, it is required that you add the new
/bin/ directory of the php folder to your PATH.
To do this:
1. Open start menu
2. Right click my computer->properties
3. Click advanced tab -> Environment variables
4. Scroll down in the second listbox for a entry called PATH
5. add this to the end ;C:/%PHP_LOCATION%/bin
where %PHP_LOCATION% is the place that you installed PHP to.
I think you have git and bash confused.
Git is a program that would be running under bash, and isn't directly related to git unless you've gone out of your way to entangle them.
Most likely, the incantation you need is
export PATH=/path/where/php/is:$PATH
And then everything will be working. Note that needs to be the path to the directory, not the binary.
the $PATH at the end is to make sure that you don't clobber your old path.
I had the same error. I found that I needed the environment variable path in this format:
/c/wamp/bin/php/php5.3.13 (instead of C:\wamp\bin\php\php5.3.13)
Using Windows 7 & Git 1.7.10.

Categories