【问题标题】:ssl certificate issue: unable to get local issuer certificate xamppssl 证书问题:无法获取本地颁发者证书 xampp
【发布时间】:2018-03-07 18:50:51
【问题描述】:

我对他们中的许多人以前遇到过的同样问题感到震惊,希望有人可以帮助我。

在我的客户端将 SSL 证书添加到服务器后,我收到此错误。

我在谷歌和论坛上搜索了一整天,但无法解决,所以最后我在这里发布。

我的代码如下:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
//curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."\cacert.pem");
curl_setopt ($ch, CURLOPT_CAPATH, dirname(__FILE__)."\cacert.pem");
curl_setopt($ch, CURLOPT_STDERR, fopen(dirname(__FILE__)."/curl_debug.txt", "w+"));
if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
exit;

我已将这两行添加到 php.ini 文件中:

[curl]
curl.cainfo="C:\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem"

[openssl]
openssl.cafile="C:\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem"

并尝试下载最新的 cacert.pem 文件

并通过给出文件的绝对路径来尝试上面的代码:

//curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."\cacert.pem");

没有任何效果,我得到的只是同样的错误:

Curl 错误:SSL 证书问题:无法获取本地颁发者证书”

我添加了“CURLOPT VERBOSE”来详细查看,以下是我收到的内容:

* Hostname in DNS cache was stale, zapped
*   Trying xxx.xxx.x.x...
* Connected to mywebsite.com (xxx.xxx.x.x) port 443 (#0)
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: C:\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem
  CApath: C:\xampp\htdocs\projects\myproject\includes\cacert.pem
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0

注意:我添加了 CAPath,因为它在未指定时显示 CAPath : None

如果有人能就上述问题给我建议,那就太好了。

非常感谢

【问题讨论】:

  • 1) 它是有效证书还是自签名证书? 2) curl 在哪里运行,是在本地开发 XAMP 上还是在主机等生产环境中?
  • SSL 是由 Comodo 发布的,它在我的本地主机上运行的本地开发 XAMPP 上
  • 尝试在路径中使用 / 而不是 \
  • 看起来 CAfile 缺少正确的证书。如果您使用来自 curl.haxx.se/docs/caextract.html 的 cacert.pem 会怎样?

标签: php ssl curl


【解决方案1】:

在 Windows XAMP 中,使用 CURL 时我必须设置 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 我知道这是某种错误。

显然,这绕过了使用 SSL 时的验证,因此它只是用于开发的解决方法。

【讨论】:

    猜你喜欢
    • 2019-04-12
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 2021-08-30
    • 2019-09-03
    相关资源
    最近更新 更多