为啥找不到 composer 命令?
Posted
技术标签:
【中文标题】为啥找不到 composer 命令?【英文标题】:Why is the composer command not found?为什么找不到 composer 命令? 【发布时间】:2017-03-14 11:24:22 【问题描述】:为什么自述文件中的作曲家指令在我如下申请时失败?
尝试如下但失败:
# uname -a
Linux signal 3.10.0-123.8.1.el7.x86_64 #1 SMP Mon Sep 22 19:06:58 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
# php --version
PHP 5.4.16 (cli) (built: Oct 31 2014 12:59:36)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
# ls
LICENSE bootstrap.php detect.php index.php
README.md composer.json hooks templates
# composer create-project whichbrowser/server .
-bash: composer: command not found
# php composer create-project whichbrowser/server .
Could not open input file: composer
编辑:
[root@signal wb]# php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') echo 'Installer verified'; else echo 'Installer corrupt'; unlink('composer-setup.php'); echo PHP_EOL;"
Installer verified
[root@signal wb]# php composer-setup.php
All settings correct for using Composer
Downloading 1.2.1...
Composer successfully installed to: /var/www/html/sip-phone/tls/website/wb/composer.phar
Use it: php composer.phar
[root@signal wb]# php -r "unlink('composer-setup.php');"
[root@signal wb]# php composer.phar create-project whichbrowser/server .
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Installing whichbrowser/server (v2.0.12)
[InvalidArgumentException]
Project directory ./ is not empty.
create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]
[root@signal wb]#
【问题讨论】:
你安装作曲家了吗?它不是 PHP 发行版的一部分,因此您必须从 getcomposer.org 安装它(如果您没有自己重命名,它通常命名为 composer.phar) 好吧,找不到 composer 二进制文件,所以它没有安装(或者不在你的路径上)。您是否像往常一样在同一台计算机/虚拟机/图像/容器上?当前目录中有 composer.phar 吗?which composer
给你任何有用的信息吗?
这是一个不同的错误。而Project directory ./ is not empty.
很清楚
php composer.phar create-project whichbrowser/server this_arg_is_the_path_of_an_empty_directory
正如它所说,您的项目目录不是空的。可能是因为那是您刚刚下载并安装 Composer 的地方。并且不要以root身份运行composer。让 create-project 为项目创建一个新目录。
【参考方案1】:
你没有安装composer,请安装:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') echo 'Installer verified'; else echo 'Installer corrupt'; unlink('composer-setup.php'); echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
编辑:
阅读如何安装:https://getcomposer.org/download/
你在非空目录下创建浏览器/服务器项目,尝试在空目录下创建项目:
mkdir ./myproject
php composer.phar create-project whichbrowser/server ./myproject
【讨论】:
您能否编辑并解释您的代码为何有效以及您的代码实际做了什么,这将有助于阅读本文的每个人都知道发生了什么。干杯:) @Hardy Rust:请参阅我的编辑部分,它不起作用。 此答案的代码在 composer 的下一个版本中将不正确。您应该只发布一个指向getcomposer.org/download 的链接。 不工作我得到关注# php composer.phar require whichbrowser/parser Could not open input file: composer.phar
yum install php-mbstring以上是关于为啥找不到 composer 命令?的主要内容,如果未能解决你的问题,请参考以下文章
为啥 composer 在 packagist.org 上找不到我的全新包?
为啥 composer 在 packagist.org 上找不到我的全新包?
Laravel 5/Composer 终端错误:sh.exe”:composer:找不到命令