简体   繁体   English

PHP Composer - 无法在 macOS Sierra 上安装 Composer

[英]PHP Composer - Unable to install composer on macOS Sierra

I'm trying to install composer running the command provided on the getcomposer.org/download documentation site:我正在尝试安装运行 getcomposer.org/download 文档站点上提供的命令的 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');"

But I get an error message saying:但我收到一条错误消息:

Warning: copy(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in Command line code on line 1

Warning: copy(): Failed to enable crypto in Command line code on line 1

Warning: copy(https://getcomposer.org/installer): failed to open stream: operation failed in Command line code on line 1
Yoshihiros-MacBook-Pro:~ yoshihiro$ php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Warning: hash_file(composer-setup.php): failed to open stream: No such file or directory in Command line code on line 1
Installer corrupt
Warning: unlink(composer-setup.php): No such file or directory in Command line code on line 1

Yoshihiros-MacBook-Pro:~ yoshihiro$ php composer-setup.php
Could not open input file: composer-setup.php

I'm also trying to install it globally but I can't get out of this message.我也在尝试在全球范围内安装它,但我无法摆脱此消息。 Please help D:请帮助D:

I had same issues but this what I did:我有同样的问题,但这就是我所做的:

  • I copy paste this into the terminal php -r "copy('http://getcomposer.org/installer', 'composer-setup.php');"我复制粘贴到终端php -r "copy('http://getcomposer.org/installer', 'composer-setup.php');" on the terminal which download the composer to the directory where you are currently In.在将 Composer 下载到您当前所在目录的终端上。

(the problem was causing because of the https protocol ) (问题是由https protocol引起的)

  • And then php composer-setup.php --install-dir=/usr/local/bin --filename=composer run this command, which installs the Composer to my bin folder so that i could run it globally.然后php composer-setup.php --install-dir=/usr/local/bin --filename=composer运行此命令,它将 Composer 安装到我的 bin 文件夹中,以便我可以全局运行它。

  • Then you have to unlink the composer php -r "unlink('composer-setup.php');"然后你必须取消链接作曲家php -r "unlink('composer-setup.php');"

  • Finally check the see the Composer installed composer -V .最后检查查看 Composer 安装的composer -V

Good Luck !祝你好运!

I had the same problem- here is the right way我有同样的问题 - 这是正确的方法

  1. clean dir > Terminal > mkdir composer清洁目录 > 终端 > mkdir composer

  2. cd composer

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

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

    vim ~/.bash_profile

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

I had same issues but this what I did:我有同样的问题,但这就是我所做的:

  • I ran curl -sS https://getcomposer.org/installer | php我跑了curl -sS https://getcomposer.org/installer | php curl -sS https://getcomposer.org/installer | php on my terminal which made composer to be installed on my PC. curl -sS https://getcomposer.org/installer | php在我的终端上安装了 Composer。
  • And then I moved Composer to my bin folder so that i could run it globally mv Composer.phar usr/local/bin/composer .然后我将 Composer 移动到我的 bin 文件夹,以便我可以全局运行它mv Composer.phar usr/local/bin/composer

It works for me as follows:它适用于我如下:

I ran我跑了

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

on my terminal which made composer to be installed on my PC.在我的终端上,它使 Composer 安装在我的 PC 上。 And then I moved Composer to my bin folder so that I could run it globally:然后我将 Composer 移动到我的 bin 文件夹,以便我可以在全局范围内运行它:

mv Composer.phar usr/local/bin/composer

The instructions in Composer official page is sometimes confusing Composer官方页面中的说明有时令人困惑

or not working on macOS Sierra.或不在 macOS Sierra 上工作。

But installation is still simple like before.Just simply run two lines of command on your Terminal.但是安装还是像以前一样简单。只需在终端上运行两行命令即可。

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

I had also the same issues to install composer after a clean install of macOS Sierra.在全新安装 macOS Sierra 后,我在安装 composer 时也遇到了同样的问题。 My solution to get it work:我让它工作的解决方案:

  1. Open your terminal打开你的终端
  2. sudo php -r "copy('http://getcomposer.org/installer', 'composer-setup.php');"
  3. sudo php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
  4. sudo php composer-setup.php
  5. sudo php -r "unlink('composer-setup.php');"
  6. sudo mv composer.phar /usr/local/bin/composer

To verify if it's all installed properly type: composer -V要验证是否已正确安装,请键入: composer -V

Please don't use any of it.请不要使用任何一个。 I'm not saying its wrong.我不是说它错了。

Please follow the link https://getcomposer.org/download/ for installing latest version of composer.请按照链接https://getcomposer.org/download/安装最新版本的 composer。

The reason is because hen you download from getcomposer.org you are downloading latest file like https://getcomposer.org/installer & composer-setup.php .原因是因为当您从getcomposer.org下载时,您正在下载最新的文件,例如https://getcomposer.org/installer & composer-setup.php

And comparing with wrong SHA384 hash_file (like e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae ), so it will not work.并与错误的 SHA384 hash_file 进行比较(如e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae

您也可以将composer.phar (这是您安装后最终得到的)放在您想要的任何位置,并使用ln -s/usr/local/bin/composer创建一个符号链接

I use this method .and works fine for me on ubuntu 17.10我使用这种方法。并且在ubuntu 17.10上对我来说效果很好

1 -create file bash 1 - 创建文件 bash

1-1 Create a directory on the desktop.And then open the terminal 1-1在桌面创建一个目录,然后打开终端

 sudo touch sh1.sh
 sudo 777 sh1.sh

2 -edited file sh1.sh writing this statements 2 -编辑文件 sh1.sh 编写此语句

 #!/bin/sh

 EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")"

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
    >&2 echo 'ERROR: Invalid installer signature'
    rm composer-setup.php
    exit 1
fi

php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RESULT=$?

exit $RESULT

3 -on terminal run 3- on 终端运行

./sh1.sh

Please just copy the link and paste it to your terminal:请复制链接并将其粘贴到您的终端:

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

Now you can run composer without any error....现在您可以毫无错误地运行 composer....

I have same problem and I try this step:我有同样的问题,我尝试这一步:

  1. Open your terminal打开你的终端

  2. Copy this code in your php folder, In My laptop, I have use lampp then I go to xampp folder.将此代码复制到您的 php 文件夹中,在我的笔记本电脑中,我使用了 lampp,然后转到 xampp 文件夹。

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

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

  1. So, if you have get this message below:因此,如果您在下面收到此消息:

All settings correct for using Composer Downloading...使用 Composer 下载的所有设置都正确...

Composer (version 2.0.8) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer Composer (version 2.0.8) 成功安装到:/usr/local/bin/composer 使用:php /usr/local/bin/composer

  1. You can copy this code:您可以复制此代码:

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

  2. Untill here you have succesfully install composer直到这里你已经成功安装了 composer

  3. Check it with this code composer使用此代码检查它composer

Thanks谢谢

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

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