php 运行 Composer 返回:“无法打开输入文件:composer.phar”

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

Running Composer returns: "Could not open input file: composer.phar"

phpsymfonywampcomposer-php

提问by user3291745

I am new to symfony2 and reading symblog. In third chapter while trying with data-fixtures I tried the command:

我是 symfony2 的新手,正在阅读symblog。在第三章尝试使用数据夹具时,我尝试了以下命令:

php composer.phar update

php composer.phar update

but I got the error:

但我得到了错误:

Could not open input file: composer.phar

Could not open input file: composer.phar

So I googled a little and tried

所以我用谷歌搜索了一下并尝试

php composer.phar install

but still getting the same error. So please guide how to deal with this composer to install new extentions or bundles like data-fixtures in symfony2 using wamp.

但仍然得到同样的错误。所以请指导如何处理这个作曲家以使用 wamp 在 symfony2 中安装新的扩展或捆绑包,如数据夹具。

回答by Chris Moschini

If you followed instructions like these:

如果您遵循以下说明:

https://getcomposer.org/doc/00-intro.md

https://getcomposer.org/doc/00-intro.md

Which tell you to do the following:

其中告诉您执行以下操作:

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

Then it's likely that you, like me, ran those commands and didn't read the next part of the page telling you to stop referring to composer.phar by its full name and abbreviate it as an executable (that you just renamed with the mv command). So this:

那么很可能你像我一样运行了这些命令并且没有阅读页面的下一部分告诉你停止引用 composer.phar 的全名并将其缩写为可执行文件(你刚刚用 mv 重命名命令)。所以这:

$ php composer.phar update friendsofsymfony/elastica-bundle

Becomes this:

变成这样:

$ composer update friendsofsymfony/elastica-bundle

回答by The Unknown Dev

I had the same problem on Windows and used a different solution. I used the Composer_Setup.exe installation file supplied by the composer website and it does a globalinstall.

我在 Windows 上遇到了同样的问题并使用了不同的解决方案。我使用了 composer 网站提供的 Composer_Setup.exe 安装文件,它进行了全局安装。

After installing, make sure your PATH variable points to the directory where composer.phar is stored. This is usually C:\ProgramData\ComposerSetup\bin(ProgramData might be a hidden directory). It goes without saying, but also be sure that the PHP executable is also in your PATH variable.

安装后,确保您的 PATH 变量指向存储 composer.phar 的目录。这通常是C:\ProgramData\ComposerSetup\binProgramData 可能是一个隐藏目录)。不用说,但也要确保 PHP 可执行文件也在您的 PATH 变量中。

You can then simply call

然后你可以简单地调用

composer install

instead of

代替

php composer.phar install

回答by Nic Wortel

Background

背景

It is helpful to know that there are two ways to install (and use) Composer: locallyas a file in your project directory, or globallyas a system-wide executable.

知道有两种安装(和使用)Composer 的方法会很有帮助:在本地作为项目目录中的文件,或作为系统范围的可执行文件在全局范围内

Installing Composer locally simply means that you are downloading a file (composer.phar- which is a PHP Archive) into your project directory. You will have to download it for every project that requires Composer.

在本地安装 Composer 只是意味着您正在将文件(composer.phar- 这是一个PHP 存档)下载到您的项目目录中。您必须为每个需要 Composer 的项目下载它。

Like a regular PHP file that you want to execute on the command line, you will have to run it with PHP:

就像您想在命令行上执行的常规 PHP 文件一样,您必须使用 PHP 运行它:

php composer.phar update

Which basically tells the phpexecutable to run the file composer.pharwith updateas argument.

这基本上告诉php可执行文件composer.pharupdate作为参数运行文件。

However, if you install it globally, you can make composer itself executable, so you can call it without php (and don't have to download it for every project). In other words, you can use composer like this:

但是,如果您全局安装它,您可以使 composer 本身可执行,因此您可以在没有 php 的情况下调用它(并且不必为每个项目都下载它)。换句话说,你可以像这样使用 composer:

composer update

Since you are executing php composer.phar update, and you are getting the error Could not open input file: composer.phar, you probably don't have composer.pharin your current directory.

由于您正在执行php composer.phar update,并且您收到错误Could not open input file: composer.pharcomposer.phar您当前目录中可能没有。

Solution

解决方案

If you have Composer installed globally, simply run composer updateinstead of php composer.phar update.

如果您全局安装了 Composer,只需运行composer update而不是php composer.phar update.

If you don't have Composer installed yet, download the PHAR using the following command:

如果您还没有安装 Composer,请使用以下命令下载 PHAR:

curl -sS https://getcomposer.org/installer | php

This will download the installerand run it using php. The installer will download the actual Composer PHAR to your current working directory, and make it executable.

这将下载安装程序并使用php. 安装程序会将实际的 Composer PHAR 下载到您当前的工作目录,并使其可执行。

To install Composer globally (I recommend this), copy the file to a location in your PATH. The exact location differs per operating system and setup, see https://getcomposer.org/doc/00-intro.md#globallyfor more information.

要全局安装 Composer(我建议这样做),请将文件复制到PATH. 确切位置因操作系统和设置而异,请参阅https://getcomposer.org/doc/00-intro.md#globally了解更多信息。

Personally, I prefer to install Composer in my home directory so I don't need sudoto install or update the composerexecutable (which can be a security risk). As I'm on Linux, I use the following command:

就我个人而言,我更喜欢在我的主目录中安装 Composer,这样我就不需要sudo安装或更新composer可执行文件(这可能存在安全风险)。因为我在 Linux 上,所以我使用以下命令:

mv composer.phar ~/.local/bin/composer

回答by Stan Smulders

If anyone else came this low on the page and still didn't find a working answer (like I did), use this:

如果其他人在页面上出现如此低的结果并且仍然没有找到有效的答案(就像我一样),请使用:

$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer.phar
$ alias composer='/usr/local/bin/composer.phar'
$ composer --version

et voila! A working composer :-)

等等!一个工作作曲家:-)

回答by purencool

I found this worked as I did not have curl installed. On Windows 8 with XAMPP installed. It will add it to your local build I use .gitignore to avoid the repo

我发现这有效,因为我没有安装 curl。在安装了 XAMPP 的 Windows 8 上。它会将它添加到您的本地构建中,我使用 .gitignore 来避免 repo

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

I got it from here: https://getcomposer.org/download/

我从这里得到它:https: //getcomposer.org/download/

回答by Achref Gassoumi

To solve this issue the first thing you need to do is to get the last version of composer :

要解决此问题,您需要做的第一件事是获取最新版本的 composer :

curl -sS https://getcomposer.org/installer | php

I recommend you to move the composer.phar file to a global “bin” directoy, in my case (OS X) the path is:

我建议您将 composer.phar 文件移动到全局“bin”目录,在我的情况下(OS X)路径是:

mv composer.phar /usr/local/bin/composer.phar

than you need to create an alias file for an easy access

比您需要创建一个别名文件以便于访问

alias composer='/usr/local/bin/composer.phar'

If everything is ok, now it is time to verify our Composer version:

如果一切正常,现在是时候验证我们的 Composer 版本了:

composer --version

Let's make composer great again.

让我们让作曲家再次伟大。

回答by Mohamed Fanane

This worked for me:

这对我有用:

composer install

Without

没有

php composer install

回答by Fabio Valencio

Use this :

用这个 :

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

回答by Muhammad Shahzad

Yesterday I was trying to install Yii2 framework on Windows 10 and I have same problem(Could not open input file: composer.phar) running this command:

昨天我试图在 Windows 10 上安装 Yii2 框架,但我在运行此命令时遇到了同样的问题(无法打开输入文件:composer.phar):

php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9

Issue is composer.phr file is not in current directory,you need to give full path composer.phr like

问题是 composer.phr 文件不在当前目录中,您需要提供完整路径 composer.phr 像

php C:\ProgramData\Composer\bin\composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9

Or you can create yii2 project using this command:

或者您可以使用以下命令创建 yii2 项目:

 composer create-project yiisoft/yii2-app-advanced advanced 2.0.9

Or

或者

composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9

回答by Kiren Siva

I had the same issue. It is solved when I made composer globally available. Now I am able to tun the commands from any where in the folder.

我遇到过同样的问题。当我让 composer 全局可用时,它就解决了。现在我可以从文件夹中的任何位置调整命令。

composer update

composer update

composer require "samplelibraryyouwant"

composer require "samplelibraryyouwant"