The “https://packagist.org/packages.json” file could not be downloaded: SSL operation failed

牧云@^-^@ 提交于 2019-12-22 17:11:09

问题


When I run the following command  

sudo composer update

then I am getting following error.

The "https://packagist.org/packages.json" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Failed to enable crypto
failed to open stream: operation failed


回答1:


I came across this issue on OSX after using Homebrew to upgrade to PHP 7.0.12.

To resolve the problem I downloaded cacert.pem using WGET.

wget http://curl.haxx.se/ca/cacert.pem

I saved that file to my home directory /Users/alex/cacert.pem. Then configured my PHP.ini file to point to that cacert location.

To do this; First locate your php.ini and run the command php --ini that should produce:

$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.0
Loaded Configuration File:         /usr/local/etc/php/7.0/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.0/conf.d

The INI file to edit is the one at the Loaded Configuration File location. Open that file in your editor of choice (Vim, etc) and find the setting openssl.cafile. This is probably commented out so uncomment it and insert the location of your cacert.pem.

You should then be able to run compose install, composer update, composer self-update, etc




回答2:


Certain Composer commands, including exec, install, and update allow third party code to execute on your system. This is from its "plugins" and "scripts" features. Plugins and scripts have full access to the user account which runs Composer. For this reason, it is strongly advised to avoid running Composer as super-user/root.

You can disable plugins and scripts during package installation or updates with the following syntax so only Composer's code, and no third party code, will execute:

composer install --no-plugins --no-scripts
composer update --no-plugins --no-scripts

The exec command will always run third party code as the user which runs composer.

In some cases, like in CI systems or such where you want to install untrusted dependencies, the safest way to do it is to run the above command.

so always run composer without sudo



回答3:


I've tried these solutions, but none of them worked for me. I know it may sounds like a dummy workaround, but this what I did in case anyone find it useful:

1) temporarily I enabled my mobile as a wifi hotspot. 2) connected my laptop to this wifi. I have my Vagrant VM here, with Laravel/Composer running. 3) I disabled all proxy environment settings (e.g. http_proxy, https_proxy, etc) within my VM. 4) Then, I successfully created my project, by using "composer global require "laravel/installer" and "composer create-project laravel/laravel" commands. 5) disconnected the wifi hotspot, and started to work normally (ethernet).

HTH. Carlos.




回答4:


You need to reboot your computer.

I had it on virtual environment Vagrant Laravel Homestead.

To fix id I did

vagrant halt
...
vagrant up



回答5:


I met this issue on Virtualbox - Ubuntu / Docker / PHP7 and fix by restarting the Ubuntu.



来源:https://stackoverflow.com/questions/40213635/the-https-packagist-org-packages-json-file-could-not-be-downloaded-ssl-oper

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!