从Packagist更新时,Composer update失败

35
执行composer install/update时,由于openssl出现以下错误:
https://packagist.org/packages.json”文件无法下载:SSL操作失败,代码为1。 OpenSSL错误消息: 错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 加密启用失败 打开流失败:操作失败 https://packagist.org 无法完全加载,包信息从本地缓存加载,可能已过期
我使用的环境是:
1.PHP 5.6.3(cli)(构建日期:2014年11月17日15:16:53) 2.XAMPP stack 5.6.3-0 3.ubuntu 14.04
composer diag 显示:
Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity: FAIL
[Composer\Downloader\TransportException] The "https://packagist.org/packages.json"  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
Checking disk free space: OK
Checking composer version: 

[Composer\Downloader\TransportException]
https://getcomposer.org/version”文件无法下载:SSL操作失败,代码为1。 OpenSSL错误消息:
错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败
启用加密失败
流打开失败:操作失败 php -r 'var_dump(openssl_get_cert_locations());' 显示:
array(8) {
["default_cert_file"]=>
string(33) "/opt/lampp/share/openssl/cert.pem"
["default_cert_file_env"]=>
string(13) "SSL_CERT_FILE"
["default_cert_dir"]=>
string(30) "/opt/lampp/share/openssl/certs"
["default_cert_dir_env"]=>
string(12) "SSL_CERT_DIR"
["default_private_dir"]=>
string(32) "/opt/lampp/share/openssl/private"
["default_default_cert_area"]=>
string(24) "/opt/lampp/share/openssl"
["ini_cafile"]=>
string(0) ""
["ini_capath"]=>
string(0) ""
}

对于php 5.5.19一切正常。


请查看此问题:https://github.com/composer/composer/issues/2798 - sectus
如果您正在使用 Kaspersky,请查看此链接:https://stackoverflow.com/a/54791481/3549317 - cespon
12个回答

32
我找到了解决方法。
我正在使用: FreeBSD 10.1 Apache2.4 PHP 5.6.3
为了找到CA文件,我运行了以下命令: > locate cacert.pem
结果是: /usr/local/lib/perl5/site_perl/5.16/Mozilla/CA/cacert.pem
然后打开php.ini文件, 将这个修改为:
;openssl.cafile=
改为:
openssl.cafile=/usr/local/lib/perl5/site_perl/5.16/Mozilla/CA/cacert.pem
注意:此指令仅适用于php 5.6.x版本。
然后重新启动Apache。

1
如果您找不到 cacert.pem 文件的副本,则可在 http://curl.haxx.se/docs/caextract.html 下载。 - redDevil
2
我正在MAC上使用PHP版本5.6.3。但是无法找到openssl.cafile=。 - Kiren S
我的Zend Framework 2应用程序可以在Ubuntu上使用php composer.phar install命令。 - shukshin.ivan
我刚刚在php 7.0中完成了所有这些工作,但它仍然不起作用(;_;)怎么回事?我也重新启动了apache。 - pythonian29033
在我的 Vagrant 环境中,使用 PHP 5.6.40 和 Ubuntu 18.04 版本可以正常工作。 - Bob Bao

12

我通过将SSL证书添加到XAMPP证书文件夹中来解决了SSL错误问题。

// navigate to a directory to save the certificate
cd /Downloads

// download a certificate
wget http://curl.haxx.se/ca/cacert.pem

// rename and move the file to the Xampp certificates folder
mv cacert.pem /Applications/XAMPP/xamppfiles/share/openssl/cert.pem

别忘了重新启动你的apache!


2
谢谢!关于Linux的信息,路径是:sudo mv cacert.pem /opt/lampp/share/openssl/cert.pem。 - Ronald Araújo
要查找位置,可以使用以下命令:php -r "print_r(openssl_get_cert_locations());"(查找 default_cert_file 的值)。 - Potherca

12

我正在使用Mac OS Sierra,在尝试使用命令/usr/local/bin/composer self-update更新composer时,一直出现以下错误:

[Composer\Downloader\TransportException]                                                          
  The "https://getcomposer.org/version" file could not be downloaded: SSL operation failed with co  
  de 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  

我按照以下步骤解决了问题:

1)使用以下命令创建本地数据库:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

2) 找到证书文件:

locate cacert.pem 

3) 检查 php.ini 文件的位置:

php --ini

4) 如果 php.ini 文件的 'Loaded Configuration File' 显示为 (none),则将文件 /etc/php.ini.default 复制到 /etc/php.ini

sudo cp /etc/php.ini.default /etc/php.ini

5)打开php.ini文件,并通过取消注释并将链接附加到证书文件位置来编辑;openssl.cafile=行:

openssl.cafile=/Users/me/.composer/cacert.pem

完成了。现在,当您运行 composer update 命令时,它将正常工作。


1
运行得非常顺利 - Gino Pane

7
我在Windows上遇到了完全相同的问题,即使添加了最新有效的证书也不行。我在代理后运行composer,因此必须添加环境变量http_proxy和https_proxy。
我的环境: PHP 5.6.33 Windows 7 64位 Composer版本1.6.3 2018-01-31 16:28:17
我下载了最新的证书CA Bundle并更新了php.ini中的以下路径,但仍然无法解决问题。
curl.cainfo = C:\Certificates\ca-bundle.crt
openssl.cafile= C:\Certificates\ca-bundle.crt
openssl.capath=C:\Certificates

接下来进行以下步骤:

1)打开谷歌浏览器并导航至https://packagist.org/

2)点击小的安全锁图标

3)点击证书有效

enter image description here

4)打开证书路径选项卡,您将看到以下路径级别

enter image description here

5) 需要导出图像中标记为1&2的证书

6) 要导出证书,点击查看证书,转到详细信息选项卡,然后点击复制到文件。

enter image description here

7)选择BASE 64编码

enter image description here

8) 点击“下一步”并将该文件保存到指定位置,对于第4步中显示的No. (2),请执行此操作。

enter image description here

9) 打开 .cer 文件并将内容复制到您在 php.ini 中配置的 .crt 文件的末尾

然后尝试运行 comport install - 这对我有用

如果您在通过代理访问站点时看到 composer 抛出 ssl 错误,则应该使用相同的过程。


6
将openssl.cafile添加到php.ini中对我也起作用了。 我直接下载证书文件,而不是寻找它: curl http://curl.haxx.se/ca/cacert.pem > cacert.pem 然后只需要将openssl.cafile设置指向它即可。

从不安全的来源(http)下载根证书是一个安全问题。只有业余人士会这样做,然后他们就会被黑客攻击。 - Daniel W.
1
@Kwadz请使用https链接,通过SSH/SFTP/SCP将文件放到您的服务器上。 - Daniel W.

5

1.

php -r "print_r(openssl_get_cert_locations());"

array(8) {
  ["default_cert_file"]=>
  string(31) "/usr/local/etc/openssl/cert.pem"
  ...
}

2.编辑php.ini文件

[openssl]
openssl.cafile=/usr/local/etc/openssl/cert.pem

2
composer clearcache

当我出现以下错误时,这个方法对我很有用:

https://packagist.org 无法完全加载,包信息已从本地缓存加载,可能已过期。


现在我遇到了以下错误:curl error 60 while downloading https://repo.packagist.org/packages.json: SSL certificate problem: unable to get local issuer certificate,我该如何解决? - Pathros

1
在Mac上使用XAMPP:
cd /Applications/XAMPP/xamppfiles/share/openssl

sudo curl -O -k http://curl.haxx.se/ca/cacert.pem

sudo mv cacert.pem cert.pem

停止和重新启动Apache。

1
我可以添加一个简单的答案。
您的问题:由于证书不正确,可能是损坏、不正确或根本不存在,因此作曲家无法下载依赖文件。
您可能最简单的解决方案:下载新证书并告诉Composer使用新证书。
步骤1:从https://curl.se/docs/caextract.html获取CA证书。
步骤2:使用以下命令来使用新证书: composer config --global cafile "<file_path_including_cacert.pem"

1

第一步: 检查证书文件位置,它将在default_cert_file键中,您可以在openssl_get_cert_locations()中找到它,这是一个php openssl函数。您可以按如下方式运行它:

$ php -r "print_r(openssl_get_cert_locations());"

在我的系统中输出
    Array
    (
        [default_cert_file] => /opt/lampp/share/openssl/cert.pem
        [default_cert_file_env] => SSL_CERT_FILE
        [default_cert_dir] => /opt/lampp/share/openssl/certs
        [default_cert_dir_env] => SSL_CERT_DIR
        [default_private_dir] => /opt/lampp/share/openssl/private
        [default_default_cert_area] => /opt/lampp/share/openssl
        [ini_cafile] => 
        [ini_capath] => 
    )

第二步:下载http://curl.haxx.se/ca/cacert.pem

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

第三步:将“certificate.pem”文件复制到“default_cert_file”位置:
$ sudo mv cacert.pem /opt/lampp/share/openssl/cert.pem

** 来自 https://github.com/composer/composer/issues/3346 **


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接