php 作曲家:找不到命令

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

Composer: Command Not Found

phpcomposer-php

提问by Brandon Buster

From within the directory holding my composer.phar file, I can't execute any composer commands.

在我的 composer.phar 文件所在的目录中,我无法执行任何 composer 命令。

I can see Composer is running when I execute

当我执行时,我可以看到 Composer 正在运行

php composer.phar 

But any direct composer statements fail.

但是任何直接的作曲家语句都失败了。

Not sure if it matters but Composer was included within a cloned repository.

不确定这是否重要,但 Composer 包含在克隆的存储库中。

I just want to install a single Oauth library, then likely not touch Composer again for several months, so I don't need to run it globally. I'm just confused why I can't run Composer from within this directory.

我只想安装一个 Oauth 库,然后可能几个月内不会再接触 Composer,所以我不需要全局运行它。我只是很困惑为什么我不能从这个目录中运行 Composer。

采纳答案by Sven

Your composer.pharcommand lacks the flag for executable, or it is not inside the path.

您的composer.phar命令缺少可执行标志,或者它不在路径内。

The first problem can be fixed with chmod +x composer.phar, the second by calling it as ./composer.phar -v.

第一个问题可以通过 来解决chmod +x composer.phar,第二个问题可以通过调用为 来解决./composer.phar -v

You have to prefix executables that are not in the path with an explicit reference to the current path in Unix, in order to avoid going into a directory that has an executable file with an innocent name that looks like a regular command, but is not. Just think of a catin the current directory that does not list files, but deletes them.

您必须为不在路径中的可执行文件加上对 Unix 中当前路径的显式引用作为前缀,以避免进入包含可执行文件的目录,该可执行文件的名称看起来像一个普通命令,但实际上不是。想想cat当前目录中的一个没有列出文件,而是删除它们。

The alternative, and better, fix for the second problem would be to put the composer.pharfile into a location that is mentioned in the path

解决第二个问题的另一种更好的方法是将composer.phar文件放入路径中提到的位置

回答by drowsyTicker

This problem arises when you have composer installed locally. To make it globally executable,run the below command in terminal

当您在本地安装 composer 时会出现此问题。要使其全局可执行,请在终端中运行以下命令

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

For CentOS 7the command is

对于CentOS 7,命令是

sudo mv composer.phar /usr/bin/composer

回答by BSB

I am using CentOS and had same problem.

我正在使用 CentOS 并且遇到了同样的问题。

I changed /usr/local/bin/composerto /usr/bin/composerand it worked.

我改变/usr/local/bin/composer/usr/bin/composer,它奏效了。

Run below command :

运行以下命令:

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

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

Verify Composer is installed or not

验证 Composer 是否安装

composer --version

composer --version

回答by Nitin Nain

MacOS:composer is available on brew now (Tested on Php7+):

MacOS:composer 现在可以在 brew 上使用(在 Php7+ 上测试):

brew install composer

Install instructions on the Composer Docs pageare quite to the point otherwise.

Composer Docs 页面上的安装说明非常重要,否则。

回答by Nishant Shah

This is for mac user, try this on terminal

这是针对 mac 用户的,在终端上试试这个

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

回答by Nanhe Kumar

Step 1 : Open Your terminal

第 1 步:打开您的终端

Step 2 : Run bellow command

第 2 步:运行波纹管命令

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

Step 3 : After installation run bellow command

第 3 步:安装后运行以下命令

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

Step 4 : Open bash_profile file create alias follow bellow steps

第 4 步:按照以下步骤打开 bash_profile 文件创建别名

           vim ~/.bash_profile

Step 5 : Add bellow line in bash_profile file

第 5 步:在 bash_profile 文件中添加波纹管

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

Step 6 : Close your terminal and reopen your terminal and run bellow command composer

第 6 步:关闭终端并重新打开终端并运行下面的命令 composer

回答by Ankur Kedia

First I did alias setup on bash / zsh profile.

首先,我在 bash / zsh 配置文件上设置了别名。

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

Then I moved composer.phar to /usr/local/bin/

然后我将 composer.phar 移动到 /usr/local/bin/

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

Then made composer executable by running

然后通过运行使作曲家可执行

sudo chmod +x composer