Laravel Guzzle: curl错误77设置证书验证位置失败

6
  • 操作系统:Ubuntu 16.04
  • PHP版本:7.2
  • CURL版本:curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3
  • Guzzle版本:6.3

我的项目目前使用了一些依赖于Guzzle的包,例如:AWS、Mailgun...然而,它经常会抛出以下错误:

error: cURL error 77: error setting certificate verify locations:
CAfile: /etc/ssl/certs
CApath: /etc/ssl/certs (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

以下是我的php.ini的一部分:

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo='/etc/ssl/certs/ca-certificates.crt'

[openssl]
; The location of a Certificate Authority (CA) file on the local     filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile='/etc/ssl/certs/ca-certificates.crt'

; If openssl.cafile is not specified or if the CA file is not found, the
; directory pointed to by openssl.capath is searched for a suitable
; certificate. This value must be a correctly hashed certificate directory.
; Most users should not specify a value for this directive as PHP will
; attempt to use the OS-managed cert stores in its absence. If specified,
; this value may still be overridden on a per-stream basis via the "capath"
; SSL stream context option.
openssl.capath='/etc/ssl/certs/'

尽管通过 ini_get() 检索是可行的且被完全识别,但这些工作都无法实现。目前,我必须通过修改 vendor/guzzlehttp/guzzle/src/Client.php 并调整默认配置为 'verify' => '/etc/ssl/certs/ca-certificates.crt' 来实现一个解决方法,然后一切正常(我认为这不是一个好的选择)。

通过 init_get() 检索

array(8) {
["default_cert_file"]=> string(21) "/usr/lib/ssl/cert.pem"
["default_cert_file_env"]=>  string(13) "SSL_CERT_FILE"
["default_cert_dir"]=>  string(18) "/usr/lib/ssl/certs"
["default_cert_dir_env"]=>  string(12) "SSL_CERT_DIR"
["default_private_dir"]=>  string(20) "/usr/lib/ssl/private"
["default_default_cert_area"]=>  string(12) "/usr/lib/ssl"
["ini_cafile"]=>  string(34) "/etc/ssl/certs/ca-certificates.crt"
["ini_capath"]=>  string(15) "/etc/ssl/certs/"
}

openssl.cafile: /etc/ssl/certs/ca-certificates.crt
curl.cainfo: /etc/ssl/certs/ca-certificates.crt

注意:我已经尝试设置~/.curlrcexport CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt,但都没有起作用。

有人有什么解决方案或线索来解决这个问题吗?


也许是因为它是 CRT 而不是 PEM? - user2428118
1个回答

24
关于“SSL证书问题:无法获取本地颁发者证书”的错误。很明显,这适用于发送CURL请求的系统(而不是服务器接收请求)。
  1. https://curl.haxx.se/ca/cacert.pem下载最新的cacert.pem文件。

  2. 将以下行添加到php.ini中(如果这是共享托管且您无法访问php.ini,则可以将其添加到public_html中的.user.ini文件中)

    curl.cainfo="/path/to/downloaded/cacert.pem"
    

    请确保在双引号内括起来的路径名称!!!

  3. 向您的网络服务器用户(如nginx或www-data)授予读取该文件的权限。

  4. sudo chown www-data /etc/ssl/certs/cacert.pem
    
  5. 最后一步,重新启动FPM和NGINX或Apache。


1
谢谢你的回答。我已经尝试过了,但不幸的是,它也没有起作用。最终,对我来说没有其他选择,只能修改guzzle包以直接设置CAfile路径。 - user2663561
这是一个非常出色的回答,解决了我的问题,而且我的问题是间歇性的错误。这应该被接受为答案。 - Dom DaFonte

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