'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:
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:
Solution 1:[1]
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');"on the terminal which download the composer to the directory where you are currently In.
(the problem was causing because of the
https protocol)
And then
php composer-setup.php --install-dir=/usr/local/bin --filename=composerrun this command, which installs the Composer to my bin folder so that i could run it globally.Then you have to unlink the composer
php -r "unlink('composer-setup.php');"Finally check the see the Composer installed
composer -V.
Good Luck !
Solution 2:[2]
I had the same problem- here is the right way
clean dir > Terminal > mkdir composer
cd composercurl -sS https://getcomposer.org/installer | phpsudo mv composer.phar /usr/local/bin/vim ~/.bash_profilealias composer="php /usr/local/bin/composer.phar"
Solution 3:[3]
I had same issues but this what I did:
- I ran
curl -sS https://getcomposer.org/installer | phpon my terminal which made composer to be installed on my PC. - And then I moved Composer to my bin folder so that i could run it globally
mv Composer.phar usr/local/bin/composer.
Solution 4:[4]
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. And then I moved Composer to my bin folder so that I could run it globally:
mv Composer.phar usr/local/bin/composer
Solution 5:[5]
The instructions in Composer official page is sometimes confusing
or not working on macOS Sierra.
But installation is still simple like before.Just simply run two lines of command on your Terminal.
- curl -sS https://getcomposer.org/installer | php
- mv composer.phar usr/local/bin/composer
Solution 6:[6]
I have same problem and I try this step:
Open your terminal
Copy this code in your php folder, In My laptop, I have use lampp then I go to xampp folder.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- So, if you have get this message below:
All settings correct for using Composer Downloading...
Composer (version 2.0.8) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer
You can copy this code:
php -r "unlink('composer-setup.php');"Untill here you have succesfully install composer
Check it with this code
composer
Thanks
Solution 7:[7]
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.
The reason is because hen you download from getcomposer.org you are downloading latest file like https://getcomposer.org/installer & composer-setup.php.
And comparing with wrong SHA384 hash_file (like e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae), so it will not work.
Solution 8:[8]
I had also the same issues to install composer after a clean install of macOS Sierra. My solution to get it work:
- Open your terminal
sudo php -r "copy('http://getcomposer.org/installer', 'composer-setup.php');"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;"sudo php composer-setup.phpsudo php -r "unlink('composer-setup.php');"sudo mv composer.phar /usr/local/bin/composer
To verify if it's all installed properly type: composer -V
Solution 9:[9]
You can also just put composer.phar (which is what you end up with after you do the install) wherever you want and create a symlink in /usr/local/bin/composer to it using ln -s
Solution 10:[10]
I use this method .and works fine for me on ubuntu 17.10
1-create file bash
1-1 Create a directory on the desktop.And then open the terminal
sudo touch sh1.sh
sudo 777 sh1.sh
2-edited file sh1.sh writing this statements
#!/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
./sh1.sh
Solution 11:[11]
Please just copy the link and paste it to your terminal:
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Now you can run composer without any error....
Solution 12:[12]
You can easily download PHP Composer by following the official documentation, here's the link
These are the steps.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"php composer-setup.phpphp -r "unlink('composer-setup.php');"sudo mv composer.phar /usr/local/bin/composer
To verify if it's all installed properly type: composer -V
This will work on both Linux and macOS.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
