php 有没有办法在 Windows 上全局安装 Composer?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12059397/
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-25 02:43:47  来源:igfitidea点击:

Is there any way to install Composer globally on Windows?

phpwindowscomposer-php

提问by gremo

I've read the global installation documentationfor Composer, but it's for *nix systems only:

我已经阅读了Composer的全局安装文档,但它仅适用于 *nix 系统:

curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

I would be such happy doing the same on Windows, that's the OS of my development machine. I would be able to run

我会很高兴在 Windows 上做同样的事情,那是我的开发机器的操作系统。我可以跑

composer update

From an arbitrary folder where composer.jsonexists. Interpreter php.exeis already in PATHvariable.

composer.json存在的任意文件夹。解释php.exe器已经在PATH变量中。

Any clue?

有什么线索吗?

回答by Lusitanian

Sure. Just put composer.phar somewhere like C:\php\composer.phar, then make a batch file somewhere within the PATH called composer.batwhich does the following:

当然。只需将 composer.phar 放在诸如 之类的地方C:\php\composer.phar,然后在 PATH 中的某处创建一个批处理文件,该文件composer.bat将执行以下操作:

@ECHO OFF
php "%~dp0composer.phar" %*

The "%*" repeats all of the arguments passed to the shell script.

"%*" 重复传递给 shell 脚本的所有参数。

Then you can run around doing composer updateall ya want!

然后你就可以composer update随心所欲地跑来跑去!

回答by giannis christofakis

Install Composer

On Windows, you can use the Composer Windows Installer.

安装作曲家

在 Windows 上,您可以使用 Composer Windows Installer

回答by Muhammed Aslam C

Go to php.exe located folder.

转到 php.exe 所在的文件夹。

C:\wamp\bin\php\php5.5.12\

C:\wamp\bin\php\php5.5.12\

open cmd there, and execute below command.

在那里打开cmd,然后执行下面的命令。

php -r "readfile('https://getcomposer.org/installer');" | php

composer.pharwill be downloaded in same folder.

composer.phar将下载到同一个文件夹中。

Create folder named composerin C://drive (or anywhere you wish, for upcoming steps, remember the path).

新建文件夹命名composerC://驱动器(或任何你希望,为即将到来的步骤,记住路径)。

move composer.pharfile to C://composerfolder.

composer.phar文件移动到C://composer文件夹。

Create composer.batfile in same folder with contents below

composer.bat在同一文件夹中创建文件,内容如下

@ECHO OFF
php "%~dp0composer.phar" %*

create file named composerwithout any extensions.

创建composer没有任何扩展名的文件。

running command type NUL > composerin CMD will help to get it done quickly,

type NUL > composer在 CMD 中运行命令将有助于快速完成它,

Open that file and place below contents inside it.

打开该文件并将下面的内容放入其中。

#!/bin/sh
dir=$(d=$(dirname "
taskkill /f /IM explorer.exe
start explorer.exe
exit
"); cd "$d" && pwd) # see if we are running in cygwin by checking for cygpath program if command -v 'cygpath' >/dev/null 2>&1; then # cygwin paths start with /cygdrive/ which will break windows PHP, # so we need to translate the dir path to windows format. However # we could be using cygwin PHP which does not require this, so we # test if the path to PHP starts with /cygdrive/ rather than /usr/bin. if [[ $(which php) == /cygdrive/* ]]; then dir=$(cygpath -m $dir); fi fi dir=$(echo $dir | sed 's/ /\ /g') php "${dir}/composer.phar" $*

Save.

节省。

Now set path, So we can access composer from cmd.

现在设置path,这样我们就可以从cmd访问composer了。

  • Show Desktop.

  • Right Click My Computer shortcut in the desktop.

  • Click Properties.

  • You should see a section of control Panel - Control Panel\System and Security\System.

  • Click Advanced System Settings on the Left menu.

  • Click Environment Variables towards the bottom of the window.

  • Select PATH in the user variables list.

  • Append your PHP Path (C:\composer) to your PATH variable, separated from the already existing string by a semi colon.

  • Click OK

  • 显示桌面。

  • 右键单击桌面上的我的电脑快捷方式。

  • 单击属性。

  • 您应该看到控制面板的一部分 - 控制面板\系统和安全\系统。

  • 单击左侧菜单上的高级系统设置。

  • 单击窗口底部的环境变量。

  • 在用户变量列表中选择 PATH。

  • 将您的 PHP 路径 (C:\composer) 附加到您的 PATH 变量,用分号与现有字符串分隔。

  • 单击确定

Restart your machine.

重新启动您的机器。

Or, restart exploreronly using below command in CMD.

或者,explorer仅在 CMD 中使用以下命令重新启动。

@ECHO OFF
SET SUBDIR=%~dp0
php %SUBDIR%/composer.phar %*

Original Article with screenshots here : http://aslamise.blogspot.com/2015/07/installing-composer-manually-in-windows-7-using-cmd.html

带有截图的原始文章:http: //aslamise.blogspot.com/2015/07/installing-composer-manually-in-windows-7-using-cmd.html

回答by Anibe Agamah

This may be useful to someone:

这可能对某人有用:

On Windows 7, if you've installed Composer using curl, it can be found in similar path:

在 Windows 7 上,如果您使用 curl 安装了 Composer,则可以在类似的路径中找到它:

C:\Users\<username>\AppData\Roaming\Composer

C:\Users\<username>\AppData\Roaming\Composer

回答by LucasBeef

Well, now this question is a bit obsolete as there is now an official installer which "will install the latest Composer version and set up your PATH so that you can just call composer from any directory in your command line."

好吧,现在这个问题有点过时了,因为现在有一个官方安装程序,它“将安装最新的 Composer 版本并设置您的 PATH,这样您就可以从命令行中的任何目录调用 composer。”

You can get it at : http://getcomposer.org/doc/00-intro.md#installation-windows

你可以在:http: //getcomposer.org/doc/00-intro.md#installation-windows

回答by Muflix

Start > Computer : Properties > Change Settings > Advanced > Environment Variables > PATH : Edit [add this string (without "") at the end of line ";C:\<path to php folder>\php5.5.3"].. open cmd and type composer thats it :-)

开始>计算机:属性>更改设置>高级>环境变量>路径:编辑[在行尾添加此字符串(不带“”)";C:\<path to php folder>\php5.5.3"]..打开cmd并输入composer就是这样:-)

回答by player-one

A bit more generic if you put the batch in the same folder as composer.phar:

如果将批处理放在与 composer.phar 相同的文件夹中,则更通用:

C:\ProgramData\ComposerSetup\bin\composer.phar

I'd write it as a comment, but code isn't avail there

我会把它写成评论,但代码在那里没有用

回答by Climberdav

I use Composer-Setup.exe and it works fine. Just in case you need to know where is the composer.phar (to use with PhpStorm) :

我使用 Composer-Setup.exe,它工作正常。以防万一您需要知道 composer.phar 在哪里(与 PhpStorm 一起使用):

##代码##

回答by Jose Ortiz

I was having the same issue and when I checked the environment in Windows 7 it was pointing to c:\users\myname\appdata\composer\version\bin which didn't exists. the file was actually located in C:\ProgramData\ComposerSetup\bin Fixed the location in environment setting and it worked

我遇到了同样的问题,当我检查 Windows 7 中的环境时,它指向不存在的 c:\users\myname\appdata\composer\version\bin。该文件实际上位于 C:\ProgramData\ComposerSetup\bin 修复了环境设置中的位置并且它起作用了

回答by Overcomer

Unfortunately, all the good answers here didn't work for me. So after installing composer on windows 10, I just had to set system variablein environment variablesand it worked.

不幸的是,这里所有的好答案都不适合我。因此,在Windows上安装10作曲家,我不得不设置system variableenvironment variables和它的工作。

Windows 10 environment variable ->system variables

Windows 10 环境变量 ->系统变量