php 'composer' 在 Windows 服务器中未被识别为内部或外部命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39724594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:59:03  来源:igfitidea点击:

'composer' is not recognized as an internal or external command in windows server

phpwindowscomposer-phpenvironment-variables

提问by danish dani

I am using windows server 2008 os. i download composer setup.exeand install to my PC . when I try install composer. I getting an error:

我正在使用 Windows Server 2008 操作系统。我下载composer setup.exe并安装到我的 PC 上。当我尝试install composer。我收到一个错误:

'composer' is not recognized as an internal or external command,

'composer' 未被识别为内部或外部命令,

eg:-

例如:-

c:\xampp\htdocs\shop>composer install
'composer' is not recognized as an internal or external command,
operable program or batch file.

My environment variable PATH is shown below:

我的环境变量PATH如下所示:

C:\xampp\php\;C:\Users\Administrator\AppData\Roaming\Composer\vendor\bin

回答by Mahan_F

For anyone coming here from Google who are facing the same issue. I just managed to solve this issue after all the other "solutions" other people suggested didn't work.

对于从 Google 来到这里并面临相同问题的任何人。在其他人建议的所有其他“解决方案”都不起作用之后,我才设法解决了这个问题。

I installed Composer properly and the Environment variable was set but it just wouldn't work.

我正确安装了 Composer 并设置了环境变量,但它不起作用。

In my case composer is installed in C:\ProgramData\ComposerSetup\binand this is exactly what is in my PATHEnvironment variable. After messing around a bit trying to fix it I saw that under System variablesunder PATHthere is something called PATHEXTI opened that and added ;.PHARto the end of it. So it ended up like this:

在我的情况下,composer 已安装C:\ProgramData\ComposerSetup\bin,这正是我的PATH环境变量中的内容。在尝试修复它之后,我看到在System variables下面PATH有一个叫做PATHEXT我打开它并添加;.PHAR到它末尾的东西。所以结果是这样的:

enter image description here

在此处输入图片说明

And this is what my PATHis now: enter image description here

这就是我PATH现在的样子: 在此处输入图片说明

I closed all file explorer windows and command prompts and started a new CMD and ran composer --versionand it worked!

我关闭了所有文件资源管理器窗口和命令提示符并启动了一个新的 CMD 并运行composer --version,它工作正常!

I hope this helps someone facing the same issue as me.

我希望这可以帮助与我面临同样问题的人。

回答by amin

I had the same problem, I kept repeating the composer installation until it was resolved this way:

我遇到了同样的问题,我一直重复 Composer 安装,直到它以这种方式解决:

1) Download the composer installer (.exe) and put it on C:/XAMPP.

1) 下载 composer installer (.exe) 并将其放在 C:/XAMPP 上。

2) Run the installer by just clicking next till the end.

2)只需单击下一步直到最后运行安装程序。

3) Open command-line (cmd) and cd to your project directory (C:/XAMPP/htdocs/myproject) and type composer and see if you have it installed.

3) 打开命令行 (cmd) 并 cd 到您的项目目录 (C:/XAMPP/htdocs/myproject) 并输入 composer 并查看您是否安装了它。

4) It should work now, let's say you want to install a PHP framework from your project directory: cmd=>composer require slim/slim "^3.0".

4)它现在应该可以工作了,假设你想从你的项目目录安装一个 PHP 框架:cmd=>composer require slim/slim "^3.0".

回答by Furquan

https://getcomposer.org/doc/00-intro.md#installation-windows

https://getcomposer.org/doc/00-intro.md#installation-windows

Close your current terminal and open a new one.

关闭您当前的终端并打开一个新终端。

回答by Md Imran hossain

I had the same problem . In my case i used the command "php composer.phar " instead of "Composer " and it worked .

我有同样的问题 。在我的情况下,我使用命令“php composer.phar”而不是“Composer”并且它起作用了。

回答by danish dani

The solution is to use complete composer path instead of composer installeg:- C:\ProgramData\ComposerSetup\bin\composer install" instead of "composer install

解决方案是使用完整的作曲家路径而不是composer install例如:-C:\ProgramData\ComposerSetup\bin\composer install" instead of "composer install

Better still, add "C:\ProgramData\ComposerSetup\bin\"to your environment variables, so that you can use "composer install".

更好的是,添加"C:\ProgramData\ComposerSetup\bin\"到您的环境变量中,以便您可以使用"composer install".

回答by Yagnesh bhalala

If u can't find composer file than follow only 2 steps
1- Download composer file from [https://getcomposer.org/download/]<click on Composer-Setup.exe>

2- Install above file at your project root dir. and give second path is your php.exe file and finally solve this issue.

回答by Punit khandelwal

just paste " echo @php "%~dp0composer.phar" %*>composer.bat " This in your Terminal where you install composer and Boom you get the solution.

只需将“ echo @php "%~dp0composer.phar" %*>composer.bat ”粘贴到您的终端中,您可以在其中安装 Composer 和 Boom,您将获得解决方案。