Composer安装时出现SSL错误

时间:2016-02-04 09:39:57

标签: ssl xampp composer-php

在将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):无法打开流:操作失败

3 个答案:

答案 0 :(得分:4)

确保您在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

但是,在获取软件包时,您将再次遇到问题,直到您修复证书问题。)

答案 1 :(得分:0)

这与我面临的问题完全相同。在我的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

答案 2 :(得分:0)

我在 Windows 上更改 php 版本时遇到了同样的问题。希望这可以帮助某人。 php.ini 没有正确的扩展名,我只需要取消注释:

extension_dir = "ext"
extension=openssl