Composer 安装时出现 SSL 错误
Posted
技术标签:
【中文标题】Composer 安装时出现 SSL 错误【英文标题】:SSL Error at Composer Install 【发布时间】:2016-05-13 20:26:49 【问题描述】:在将 Composer 安装到 XAMPP 时,我遇到了一些错误。我的系统操作系统是 Windows 7,我该如何解决这个问题并安装 Composer?
下载失败:file_get_contents():SSL 操作失败,代码为 1。OpenSSL 错误消息: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 file_get_contents():无法启用加密 file_get_contents(https://getcomposer.org/composer.phar.sig):打开流失败:操作失败 下载失败:file_get_contents():SSL 操作失败,代码为 1。OpenSSL 错误消息: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 file_get_contents():无法启用加密 file_get_contents(https://getcomposer.org/composer.phar.sig):打开流失败:操作失败
【问题讨论】:
这是为我解决的问题:***.com/a/57377300/470749 【参考方案1】:确保您在php.ini
中配置了ca 证书的路径:
curl.cainfo=/full/path/to/ssl/certs/ca-bundle.crt
openssl.cafile=/full/path/to/ssl/certs/ca-bundle.crt
如果您没有 ca 证书包,请下载:
https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt
安装 Composer(不使用 cURL):
php -r "readfile('https://getcomposer.org/installer');" | php
或者,安装 Composer(使用 cURL):
curl -sS https://getcomposer.org/installer | php
(如果这不起作用,只需通过浏览器下载 Composer PHAR。
https://getcomposer.org/composer.phar
但是,在获取包时,您将再次遇到该问题,直到您修复证书问题。)
【讨论】:
我已经下载了 "ca-bundle.crt" 文件 "C:\xampp\php" 之后我添加了两行 php.ini 文件,curl.cainfo="C:\xampp\php \ca-bundle.crt" openssl.cafile="C:\xampp\php\ca-bundle.crt",在我尝试安装后会出现同样的错误,你能帮帮我吗 @ranjith 可能你需要重启你的 apache 服务 这是解决证书问题的简单方法:***.com/a/57377300/470749【参考方案2】:这与我面临的问题完全相同。在我的 Windows 7 机器上安装 Composer 安装程序时,出现以下错误:
The "https://getcomposer.org/versions" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Failed to enable crypto
failed to open stream: operation failed
试过这个:
$ curl -sS https://getcomposer.org/installer | php
stdin is not a tty
curl: (60) SSL certificate problem: self signed certificate in certificate chain
More details here: https://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
还有这个:
$ ping getcomposer.org
Pinging getcomposer.org [87.98.253.108] with 32 bytes of data:
Reply from 87.98.253.108: bytes=32 time=137ms TTL=47
Reply from 87.98.253.108: bytes=32 time=127ms TTL=47
Reply from 87.98.253.108: bytes=32 time=127ms TTL=47
Reply from 87.98.253.108: bytes=32 time=127ms TTL=47
Ping statistics for 87.98.253.108:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 127ms, Maximum = 137ms, Average = 129ms
我的 PHP 版本是:
$ php -v
PHP 5.5.37 (cli) (built: Jun 22 2016 16:14:46)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
我在 php.ini 中启用了以下列表:
extension=php_curl.dll
extension=php_openssl.dll
curl.cainfo="C:/xampp/php/extras/certs/cacert.pem"
openssl.cafile="C:/xampp/php/extras/certs/cacert.pem"
我从https://curl.haxx.se/ca/cacert.pem 下载 cacert.pem 的地方
我在安装时缺少添加代理设置,添加后它就像魅力一样! :)
http://username:password@your_proxy:your_port
【讨论】:
【参考方案3】:我在 Windows 上更改 php 版本时遇到了同样的问题。希望这可以帮助某人。 php.ini 没有正确的扩展名,我只需要取消注释:
extension_dir = "ext"
extension=openssl
【讨论】:
以上是关于Composer 安装时出现 SSL 错误的主要内容,如果未能解决你的问题,请参考以下文章
安装 Laravel 时出现 Composer 错误“无法解码响应:zlib_decode():数据错误”
安装 rubygems 时出现 SSL 错误,无法从“https://rubygems.org/”中提取数据
cURL 错误 60:尝试使用 symfony 时出现 ssl 认证问题