简体   繁体   English

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

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

I am new to symfony2 and reading symblog .我是 symfony2 的新手,正在阅读symblog In third chapter while trying with data-fixtures I tried the command:在尝试使用数据夹具的第三章中,我尝试了以下命令:

php composer.phar update

but I got the error:但我得到了错误:

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 中安装新的扩展或捆绑包,如数据固定装置。

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

$ php composer.phar update friendsofsymfony/elastica-bundle

Becomes this:变成这样:

$ composer update friendsofsymfony/elastica-bundle

I had the same problem on Windows and used a different solution.我在 Windows 上遇到了同样的问题并使用了不同的解决方案。 I used the Composer_Setup.exe installation file supplied by the composer website and it does a global install.我使用了 composer 网站提供的 Composer_Setup.exe 安装文件,它进行了全局安装。

After installing, make sure your PATH variable points to the directory where composer.phar is stored.安装后,确保您的 PATH 变量指向存储 composer.phar 的目录。 This is usually C:\\ProgramData\\ComposerSetup\\bin ( ProgramData might be a hidden directory ).这通常是C:\\ProgramData\\ComposerSetup\\binProgramData 可能是一个隐藏目录)。 It goes without saying, but also be sure that the PHP executable is also in your PATH variable.不用说,但也要确保 PHP 可执行文件也在您的 PATH 变量中。

You can then simply call然后你可以简单地调用

composer install

instead of代替

php composer.phar install

Background背景

It is helpful to know that there are two ways to install (and use) Composer: locally as a file in your project directory, or globally as 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.在本地安装 Composer 意味着您正在将文件( composer.phar - 这是一个PHP 存档)下载到您的项目目录中。 You will have to download it for every project that requires Composer.您必须为每个需要 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 php executable to run the file composer.phar with update as argument.这基本上告诉php可执行文件以update作为参数运行文件composer.phar

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).但是,如果您全局安装它,您可以使 composer 本身可执行,因此您可以在没有 php 的情况下调用它(并且不必为每个项目都下载它)。 In other words, you can use composer like this:换句话说,你可以像这样使用 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.phar in your current directory.由于您正在执行php composer.phar update ,并且您收到错误Could not open input file: composer.phar ,您当前目录中可能没有composer.phar

Solution解决方案

If you have Composer installed globally, simply run composer update instead 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 installer and run it using php .这将下载安装程序并使用php运行它。 The installer will download the actual Composer PHAR to your current working directory, and make it executable.安装程序会将实际的 Composer PHAR 下载到您当前的工作目录,并使其可执行。

To install Composer globally (I recommend this), copy the file to a location in your PATH .要全局安装 Composer(我建议这样做),请将文件复制到PATH某个位置。 The exact location differs per operating system and setup, see https://getcomposer.org/doc/00-intro.md#globally for more information.确切位置因操作系统和设置而异,请参阅https://getcomposer.org/doc/00-intro.md#globally了解更多信息。

Personally, I prefer to install Composer in my home directory so I don't need sudo to install or update the composer executable (which can be a security risk).就我个人而言,我更喜欢在我的主目录中安装 Composer,因此我不需要sudo来安装或更新composer可执行文件(这可能存在安全风险)。 As I'm on Linux, I use the following command:因为我在 Linux 上,所以我使用以下命令:

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

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 :-)一个工作作曲家:-)

I found this worked as I did not have curl installed.我发现这有效,因为我没有安装 curl。 On Windows 8 with XAMPP installed.在安装了 XAMPP 的 Windows 8 上。 It will add it to your local build I use .gitignore to avoid the repo它会将它添加到您的本地构建中,我使用 .gitignore 来避免 repo

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

I got it from here: https://getcomposer.org/download/我从这里得到它: https : //getcomposer.org/download/

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.让我们让作曲家再次伟大。

This worked for me:这对我有用:

composer install

Without没有

php composer install

在命令行中运行以下命令:
curl -sS https://getcomposer.org/installer | php

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

I had the same issue.我遇到过同样的问题。 It is solved when I made composer globally available.当我让 composer 全局可用时,它就解决了。 Now I am able to tun the commands from any where in the folder.现在我可以从文件夹中的任何位置调整命令。

composer update

composer require "samplelibraryyouwant"

用这个 :

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

Easy answer, navigate to the directory where you already have the composer.json file that you want to run (ideally your project folder) then download composer into the same folder, then instantly run the install command like so:简单回答,导航到您已经拥有要运行的 composer.json 文件的目录(最好是您的项目文件夹),然后将 composer 下载到同一文件夹中,然后立即运行安装命令,如下所示:

 php composer.phar install

This will automatically find the composer.json and run your required scripts.这将自动找到 composer.json 并运行您所需的脚本。 Good luck.祝你好运。 This stuff is a breeze for terminal wizards and totally bizarre to the rest of us这些东西对于终端向导来说是轻而易举的,而对于我们其他人来说则完全奇怪

I am using windows 8.0.我正在使用 Windows 8.0。 In my case to install or update i just use composer install or something else instead of php composer.phar.在我安装或更新的情况下,我只使用 composer install 或其他东西而不是 php composer.phar。 This worked for me like这对我有用

composer require google/apiclient:1.*

Hi friends, follow the steps to fix this issue in MAC OS嗨朋友们,请按照步骤在 MAC OS 中解决此问题

  • Step 1: first run the command in Terminal with your project directory第 1 步:首先在终端中使用您的项目目录运行命令

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

  • Step 2: Move the composer.phar in your project directory第 2 步:将 composer.phar 移动到您的项目目录中

    $ mv composer.phar /Applications/MAMP/htdocs/bashrushAPI/composer.phar $ mv composer.phar /Applications/MAMP/htdocs/bashrushAPI/composer.phar

  • Step 3: Setup alias the composer第 3 步:设置别名作曲家

    $ alias composer='/Applications/MAMP/htdocs/bashrushAPI/composer.phar' $ alias composer='/Applications/MAMP/htdocs/bashrushAPI/composer.phar'

  • Step 4: Check the composer version now第 4 步:立即检查 Composer 版本

    $ composer --version $作曲家 --version

    Composer version 1.7.2 2018-08-16 16:57:12

  • Step 5: Confirm the project folders and file placed on bellow第五步:确认下面放置的项目文件夹和文件

    $ ls $ls

    CONTRIBUTING.md docker-compose.yml templates README.md logs tests composer.json phpunit.xml vendor composer.lock public composer.phar src

  • Step 6: Now update composer第 6 步:现在更新作曲家

    $ composer.phar update $ composer.phar 更新

    Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files

  • Step 7: Run your sample project第 7 步:运行您的示例项目

    $ php composer.phar start $ php composer.phar 开始

    php -S localhost:8080 -t public [Thu Sep 27 03:16:11 2018] ::1:51177 [200]: / [Thu Sep 27 03:16:11 2018] ::1:51178 [404]: /favicon.ico - No such file or directory

To googlers who installed composer via HomeBrew : make a symbolic link for /usr/local/bin/composer对于通过 HomeBrew 安装composerHomeBrew :为 /usr/local/bin/composer 创建一个符号链接

ln -s /usr/local/bin/composer /usr/local/bin/composer.phar

I got this error "Could not open input file: composer.phar" while installing Yii2 using below mentioned command.使用下面提到的命令安装 Yii2 时出现此错误“无法打开输入文件:composer.phar”

php composer.phar create-project yiisoft/yii2-app-basic basic php composer.phar create-project yiisoft/yii2-app-basic 基本

Solutions which worked for me was, I changed the command to对我有用的解决方案是,我将命令更改为

composer create-project yiisoft/yii2-app-basic basic composer create-project yiisoft/yii2-app-basic 基础

I hope it help!我希望它有所帮助!

在此处输入图片说明

your composer.phar should be placed in above way.您的 composer.phar 应按上述方式放置。

For windows, I made composer.cmd and used the below text:对于 Windows,我制作了 composer.cmd 并使用了以下文本:

php c:\programs\php\composer.phar %*

where composer.phar is installed and c:\\programs\\php\\ is added to my path.安装 composer.phar 并将 c:\\programs\\php\\ 添加到我的路径中。

Not sure why this isn't done automatically.不知道为什么这不是自动完成的。

For Windows10 Pro, Following steps fix the issue.对于 Windows10 专业版,以下步骤可解决此问题。 select properties check the Unblock program option.选择属性检查取消阻止程序选项。 run the installer, run the command CMD with Admin rights.运行安装程序,使用管理员权限运行命令 CMD。 At command promp run composer --version to make sure it is globally installed.在命令提示符下运行composer --version以确保它已全局安装。 you should be able to now run composer require drush/drush This is for drush dependency using composer.你现在应该能够运行composer require drush/drush这是使用 composer 的 drush 依赖。

Just open cmd as Administrator and go into your project folder and check it is working or not using composer command.只需以管理员身份打开 cmd 并进入您的项目文件夹并使用 composer 命令检查它是否正常工作。

The above error is because of the composer is not accessible globally.上述错误是因为 Composer 无法全局访问。 So you need to run "cmd" as Administrator.所以你需要以管理员身份运行“cmd”。

This is working fine for me.这对我来说很好用。

If you are using Ubuntu/Linux and you are trying to run如果您使用的是 Ubuntu/Linux 并且您正在尝试运行

php composer.phar require intervention/image on your command line. php composer.phar require intervention/image在命令行上php composer.phar require intervention/image

Use sudo composer require intervention/image instead.改用sudo composer require intervention/image This will give you want you are looking for.这会给你想要你正在寻找的。

I had an issue getting a package.json's script to run composer dumpautoload .我在获取 package.json 的脚本来运行composer dumpautoload时遇到了问题。

I had the file /usr/local/bin/composer.phar , and also the file ~/.bash_profile (on OSX) contained:我有文件/usr/local/bin/composer.phar ,还有文件~/.bash_profile (在 OSX 上)包含:

alias composer="php /usr/local/bin/composer.phar"

This allowed composer to work from the command line, but it didn't allow scripts to execute composer.这允许composer从命令行工作,但不允许脚本执行 composer。

The fix was this:修复是这样的:

$ cd /usr/local/bin
$ mv composer.phar composer
$ sudo chmod +x composer // +x allows the file to be executable, such as by CLI scripts

But that yielded this error Could not open input file: /usr/local/bin/composer.phar但这产生了这个错误Could not open input file: /usr/local/bin/composer.phar

The fix was to update ~/.bash_profile (sudo nano ~/.bash_profile), and change the composer alias to:解决方法是更新~/.bash_profile (sudo nano ~/.bash_profile),并将作曲家别名更改为:

alias composer="php /usr/local/bin/composer"

# ie: `.phar` extension removed

Now everything is behaving as expected.现在一切都按预期进行。

Your composer.phar must be in Source files.您的composer.phar必须在源文件中。 I had same problem and I just cut my composer.phar into mine framework-standard-edition folder, where is my whole strong text project.我遇到了同样的问题,我只是将我的 composer.phar 剪切到我的framework-standard-edition文件夹中,我的整个强文本项目在哪里。

if the composer is already install all you need is to know where the composer.phar file is (its directory) after that you move to your symfony project where you have the composer.json and from that directory you execute your composer.phar file.如果已经安装了 Composer,您只需要知道 composer.phar 文件在哪里(它的目录),然后移动到您的 symfony 项目,在那里您有 composer.json 并从该目录执行您的 composer.phar 文件。 In windows here is what you have to do.在 Windows 中,这是您必须做的。

symfony project directory_where_composer.json_is>php the_directory_where_composer.phar_is/composer update 

That's all就这样

use two steps .使用两个步骤。

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

sudo php composer.phar update须藤 php composer.phar 更新

You can do你可以做

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

The -sS flag meaning don't show progress, do show errors -sS 标志表示不显示进度,只显示错误

and then进而

php composer.phar install

from: How do I get cURL to not show the progress bar?来自: 如何让 cURL 不显示进度条?

https://packagist.org/ https://packagist.org/

I've reach to this problem when trying to install composer on a Window 7 machine from http://getcomposer.org/download page.我在尝试从http://getcomposer.org/download页面在 Window 7 机器上安装 composer 时遇到了这个问题。 As there was an existing compose version (provided by acquia Dev Desktop tool) the installation fails and the only chance was to fix this issue manually.由于存在现有的 compose 版本(由 acquia Dev Desktop 工具提供),安装失败,唯一的机会是手动修复此问题。 (or to remove Dev Desktop tool composer). (或删除 Dev Desktop 工具 composer)。

Anyway the error message is quite straightforward (Could not open input file: composer.phar), we should then tell the system where the file is located.无论如何,错误消息非常简单(无法打开输入文件:composer.phar),然后我们应该告诉系统文件所在的位置。

Edit composer.bat file and should look like:编辑 composer.bat 文件,应该如下所示:

@SET PATH=C:\Program Files (x86)\DevDesktop\php5_4;%PATH%
php.exe composer.phar %*

See that composer.phar doesn´t have a file path.看到 composer.phar 没有文件路径。 When standing in a different folder than the one where composer.phar is located the system won´t be able to find it.当站在与 composer.phar 所在文件夹不同的文件夹中时,系统将无法找到它。 So, just complete the composer.phar file path:所以,只需完成 composer.phar 文件路径:

@SET PATH=C:\Program Files (x86)\DevDesktop\php5_4;;%PATH%
SET composerScript=composer.phar
php.exe "%~dp0%composerScript%" %*

Reopen your window console and that should do the trick.重新打开您的窗口控制台,这应该可以解决问题。

EDIT: this has an issue because it always uses %~dp0%composerScript% folder as composer execution.编辑:这有一个问题,因为它总是使用 %~dp0%composerScript% 文件夹作为作曲家执行。 Then all configurations are done in that folder (besides standing on your current project folder) and not in your project folder.然后所有配置都在该文件夹中完成(除了站在您当前的项目文件夹中)而不是在您的项目文件夹中。

So far I haven't found a was to make a manual composer installation to work globally on Windows.到目前为止,我还没有发现可以手动安装 Composer 以在 Windows 上全局工作。 Perhaps you should go ahead with composer for windows installation mentioned above.也许你应该继续使用 composer 进行上面提到的 windows 安装。

Do not access the composer by composer composer.pher install不要通过 composer composer.pher install 访问 composer

use composer install使用作曲家安装

You can just try this command if you're already installed the Composer :如果你已经安装了 Composer ,你可以试试这个命令:

composer update 

or if you want add some bundle to your composer try this :或者如果你想向你的作曲家添加一些包,试试这个:

composer require "/../"

use composer alone without php在没有 php 的情况下单独使用 composer

like :喜欢 :

composer create-project --prefer-dist --stability=dev developeruz/yii-vue-app basic

I have fixed the same issue with below steps我已经通过以下步骤解决了同样的问题

  1. Open project directory Using Terminal ( which you are using ie mintty )使用终端打开项目目录(您正在使用即 mintty
  2. Now install composer within this directory as per given directions on https://getcomposer.org/download/现在按照https://getcomposer.org/download/ 上的给定说明在此目录中安装 composer

php -r "copy(' https://getcomposer.org/installer ', 'composer-setup.php');" php -r "copy(' https://getcomposer.org/installer ', 'composer-setup.php');"

php -r "if (hash_file('SHA384', 'composer-setup.php') === 'the-provided-hash-code') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php -r "if (hash_file('SHA384', 'composer-setup.php') === 'the-provided-hash-code') { echo '安装程序已验证'; } else { echo '安装程序损坏'; 取消链接('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php php -r "unlink('composer-setup.php');" php composer-setup.php php -r "unlink('composer-setup.php');"

  1. Now run your command.现在运行你的命令。

Everything is working fine now because the composer.phar file is available within the current project directory.现在一切正常,因为composer.phar文件在当前项目目录中可用。

thanks谢谢

With me it works just you need the file composer.phar and composer.json in the current project.对我来说,它只需要当前项目中的文件composer.pharcomposer.json The command is命令是

php composer.phar update 

Command like this :像这样的命令:

composer.phar require intervention/image

error: composer.phar: command not found错误:composer.phar:找不到命令

I solved the problem by following this process我按照这个过程解决了这个问题

i set the composer globally and renamed composer.phar to composer then run this command composer require intervention/image .我全局设置了 composer 并将composer.phar重命名为composer然后运行这个命令composer require intervention/image and now it's working fine现在它工作正常

I know that maybe my answer is too specific for a embedded QNAP server, but I ended here trying to install Yii: 我知道也许我的答案对于嵌入式QNAP服务器来说太具体了,但是我在这里结束了尝试安装Yii的操作:

For me, inside a QNAP NAS through PuTTY, after trying all tricks above, and updating PATH to no avail, the only cmd line that works is: 对我来说,在通过上述所有技巧将QNAP NAS内通过PuTTY进行操作之后,将PATH更新为无用之后,唯一有效的cmd行是:

 /mnt/ext/opt/apache/bin/php /usr/local/bin/composer create-project yiisoft/yii2-app-basic basic

Of course, adapt your path accordingly... 当然,相应地调整自己的道路...

If I do a which composer , I have a correct answer, but if I do a which php nothing returns. 如果我做一个which composer ,我有一个正确的答案,但是如果我做一个which php什么也不会返回。

Besides that, trying to run 除此之外,尝试跑步

/mnt/ext/opt/apache/bin/php composer create-project yiisoft/yii2-app-basic basic

or referring to 或指

composer.phar

didn't worked too... 也不行...

我处理类似问题的简单方法是-使用cd命令提示符导航到我的项目文件夹-在cdm中键入composer以确保其已安装-如果是,则键入composer require ../您打算安装的扩展名

IF want to create composer.phar file in any folder follow this command.如果想在任何文件夹中创建 composer.phar 文件,请遵循此命令。

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === 'c5b9b6d368201a9db6f74e2611495f369991b72d9c8cbd3ffbc63edff210eb73d46ffbfce88669ad33695ef77dc76976') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

I have been facing the same issue till I used the following command.在使用以下命令之前,我一直面临同样的问题。

composer self-update

Hope this works for you too!希望这对你也有用!

If not, You can check on the entire release here https://blog.packagist.com/composer-2-0-is-now-available/如果没有,您可以在此处查看整个版本https://blog.packagist.com/composer-2-0-is-now-available/

This is very easy, just run without the 'PHP' prefix.这非常简单,只需在没有“PHP”前缀的情况下运行即可。

composer.phar update

This should work.这应该工作。

for windows :)对于 windows :)

composer update
composer self-update 

you'd been asked for user permission,你被要求获得用户许可,

and one more command:还有一个命令:

composer require that_extention_you_want 

(instead of your first one: php composer.phar that_extention_you_want ) (而不是你的第一个: php composer.phar that_extention_you_want

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM