我在Windows 7上运行PHP Version 5.6.3作为XAMPP的一部分。

当我尝试使用Mandrill API时,我得到以下错误:

未捕获的异常“Mandrill_HttpError”与消息“API调用消息/发送模板失败:SSL证书问题:无法获得本地颁发者证书”

我已经尝试了我在StackOverflow上读到的所有内容,包括将以下内容添加到php.ini文件:

curl.cainfo = "C:\xampp\php\cacert.pem"

当然也下载到了cacert。来自http://curl.haxx.se/docs/caextract.html的Pem文件

但是在这之后,重新启动XAMPP和Apache服务器,但仍然得到相同的错误。

我真的不知道还能试什么。

有没有人能建议我还能尝试些什么?


编者注:禁用SSL验证存在安全隐患。如果不验证SSL/HTTPS连接的真实性,恶意攻击者可以模拟可信端点(如GitHub或其他远程Git主机),您将容易受到中间人攻击。 在使用此解决方案之前,请确保您完全理解安全问题。

我在mandrilli .php文件第65行后也有同样的问题,它说$this->ch = curl_init();

增加以下两行:

curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);

这解决了我的问题,并使用localhost发送电子邮件,但我建议不要在live版本上使用它。在您的活动服务器上,代码应该可以在没有此代码的情况下工作。


当你浏览http://curl.haxx.se/docs/caextract.html页面时,你会注意到一个用大字母写的部分:

RSA-1024把

阅读本文,然后下载包含“RSA-1024”证书的证书版本。 https://github.com/bagder/ca-bundle/blob/e9175fec5d0c4d42de24ed6d84a06d504d5e5a09/ca-bundle.crt

这些将与Mandrill一起工作。

禁用SSL是一个坏主意。


终于让这个工作了!

Download the certificate bundle. Put it somewhere. In my case, that was c:\wamp\ directory (if you are using Wamp 64 bit then it's c:\wamp64\). Enable mod_ssl in Apache and php_openssl.dll in php.ini (uncomment them by removing ; at the beginning). But be careful, my problem was that I had two php.ini files and I need to do this in both of them. One is the one you get from your WAMP taskbar icon, and another one is, in my case, in C:\wamp\bin\php\php5.5.12\ Add these lines to your cert in both php.ini files: curl.cainfo="C:/wamp/cacert.pem" openssl.cafile="C:/wamp/cacert.pem" Restart Wamp services.


谢谢@Mladen Janjetovic,

你的建议在安装了放大器的mac上对我有用。

复制:http://curl.haxx.se/ca/cacert.pem

: /应用程序/ ampp /额外的/ etc / openssl /组/ cacert.pem

用这个路径更新php.ini并重新启动Apache:

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo="/Applications/AMPPS/extra/etc/openssl/certs/cacert.pem"
openssl.cafile="/Applications/AMPPS/extra/etc/openssl/certs/cacert.pem"

并在windows AMPPS安装中应用了相同的设置,效果也很好。

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo="C:/Ampps/php/extras/ssl/cacert.pem"
openssl.cafile="C:/Ampps/php/extras/ssl/cacert.pem"

: wamp也是一样。

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo="C:/wamp/bin/php/php5.6.16/extras/ssl/cacert.pem"
openssl.cafile="C:/wamp/bin/php/php5.6.16/extras/ssl/cacert.pem"

如果您正在寻找使用SAN为localhost生成新的SSL证书,那么本文中的步骤在Centos 7 / Vagrant / Chrome浏览器上对我有效。


上面的步骤虽然有帮助,但在Windows 8上并不适用。我不知道其中的关联,但以下步骤是有效的。基本上是cacert的变化。pem文件。希望这能帮助到一些人。

下载cacert。Pem文件: http://curl.haxx.se/docs/caextract.html 将该文件保存在PHP安装文件夹中。(例如:如果使用xampp -保存在c:\Installation_Dir\xampp\php\cacert.pem)。 打开你的php.ini文件,添加这些行: curl.cainfo = " C: \ Installation_Dir \ xampp \ php \ cacert.pem” openssl.cafile = " C: \ Installation_Dir \ xampp \ php \ cacert.pem” 重新启动Apache服务器应该就能解决问题了(只需停止并启动 根据需要提供服务)。


注意:关闭SSL验证功能存在安全影响。如果不验证SSL/HTTPS连接的真实性,恶意攻击者可以模拟可信端点(如GitHub或其他远程Git主机),您将容易受到中间人攻击。 在使用此解决方案之前,请确保您完全理解安全问题。

我发现新的解决方案没有任何必要的认证调用curl只添加两行代码。

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

我在AppVeyor开发应用时也遇到了同样的问题。

下载https://curl.haxx.se/ca/cacert.pem到c:\php 开启openssl echo extension=php_openssl.dll >> c:\php\php.ini 找到certificateecho curl.cainfo=c:\php\cacert。Pem >> c:\php\php.ini


如果以上解决方案都不适用,请尝试将XAMPP安装更新到新版本。

我用php 5.5.11运行XAMPP,同样的代码不能工作,我用php 5.6.28升级到XAMPP,上面的解决方案工作了。

此外,只更新PHP也不工作,似乎是XAMPP版本的apache和PHP设置的组合。

希望它能帮助到别人。


如果你不能访问php.ini,添加这段代码(在$ch = curl_init();行)适合我:

$certificate_location = "C:\Program Files (x86)\EasyPHP-Devserver-16.1\ca-bundle.crt"; // modify this line accordingly (may need to be absolute)
curl_setopt($ch, CURLOPT_CAINFO, $certificate_location);
curl_setopt($ch, CURLOPT_CAPATH, $certificate_location);

然后,您只需要下载ca-bundle。CRT并保存到您在$certificate_location中指定的位置。


注意:关闭SSL验证功能存在安全影响。如果不验证SSL/HTTPS连接的真实性,恶意攻击者可以模拟可信端点(如GitHub或其他远程Git主机),您将容易受到中间人攻击。 在使用此解决方案之前,请确保您完全理解安全问题。

详细阐述了服务器部署的上述答案。

$hostname = gethostname();
if($hostname=="mydevpc")
{
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}

应该在部署时不影响服务器的情况下完成开发环境的技巧。


你可以试试这个:

$client = new Client(env('API_HOST'));
$client->setSslVerification(false);

测试在guzzle/guzzle 3.*


我有非常简单的解决这个问题。您可以在没有任何证书文件的情况下完成此操作。

注意,此解决方案适用于本地系统,而不适用于客户端服务器和生产服务器。

继续Laravel根文件夹-> vendor -> guzzlehttp -> guzzle -> src

打开Client.php

查找$defaults数组。看起来像这样。

$defaults = [
    'allow_redirects' => RedirectMiddleware::$defaultSettings,
    'http_errors'     => true,
    'decode_content'  => true,
    'verify'          => true,
    'cookies'         => false
];

现在主要工作是更改验证键的值..

'verify'          => false,

所以在这之后,它将不会检查SSL证书为CURL请求…这个解决方案对我来说就是工作。经过多次研究,我找到了这个解决方案…


编者注:禁用SSL验证存在安全隐患。如果不验证SSL/HTTPS连接的真实性,恶意攻击者可以模拟可信端点(如GitHub或其他远程Git主机),您将容易受到中间人攻击。 在使用此解决方案之前,请确保您完全理解安全问题。

我试过了,很管用

open

vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php

改变这个

 $conf[CURLOPT_SSL_VERIFYHOST] = 2;
 $conf[CURLOPT_SSL_VERIFYPEER] = true;

这个

$conf[CURLOPT_SSL_VERIFYHOST] = 0;
$conf[CURLOPT_SSL_VERIFYPEER] = FALSE;

我得到的错误如下:

failed loading cafile stream: `C:\xamppPhp\apache\bin\curl-ca-bundle.crt`

我用的是windows电脑。所以我遵循以下步骤。

1. I have downloaded .pem file from " https://curl.haxx.se/docs/caextract.html "

2. Then I kept the downloaded file inside  "C:/xamppPhp/apache/bin/" folder and renamed the same downloaded file to "curl-ca-bundle.crt".

3. I restarted XAMPP and cleared the cache.
4. It's done.

希望它能帮助到一些人


我在本地系统中遇到过类似的问题,但在活动服务器中没有。我还提到了另一个解决方案在此页之前,但这是不工作在本地主机。所以找到一个新的解决方案,这是在本地主机wamp服务器工作。

cURL错误#:SSL证书问题:无法获得本地颁发者 证书

有时系统无法找到您的cacert。Pem在你的硬盘里。所以你可以在你要使用CURL的代码中定义它

请注意,我正在为此满足所有条件,如OPEN-SSL库活动和其他事情。

检查CURL的代码。

 $curl = curl_init();
 curl_setopt_array($curl, array(
            CURLOPT_URL =>$url,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_RETURNTRANSFER=> true,
        ));
curl_setopt($curl, CURLOPT_CAINFO, "f:/wamp/bin/cacert.pem"); // <------ 
curl_setopt($curl, CURLOPT_CAPATH, "f:/wamp/bin/cacert.pem"); // <------
$response = json_decode(curl_exec($curl),true);
$err = curl_error($curl);
curl_close($curl);

但这种解决方案可能无法工作在现场服务器。因为cacert.pem的绝对路径


我有一个适当的解决这个问题的办法,让我们试着了解这个问题的根本原因。当无法使用系统证书存储中的根证书验证远程服务器ssl或远程ssl未与链证书一起安装时,就会出现此问题。如果您的linux系统具有root ssh访问权限,那么在这种情况下,您可以尝试使用以下命令更新您的证书存储:

update-ca-certificates

如果仍然不起作用,那么您需要在证书存储中添加远程服务器的根证书和临时证书。您可以先下载根证书和中间证书,添加到/usr/local/share/ca-certificates目录下,然后执行update-ca-certificates命令。这应该能奏效。类似地,对于windows,您可以搜索如何添加根证书和中间证书。

解决此问题的另一种方法是要求远程服务器团队将ssl证书作为域根证书、中间证书和根证书的捆绑添加。


可能发生此错误的另一个原因是,如果CA包已从系统中删除(并且在CA -certificates中不再可用)。

这是GeoTrust全球CA目前的情况,该CA(除其他外)用于为用于推送通知的APNS签署苹果证书。

更多详细信息可以在错误报告中找到:https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=962596

您可以手动添加GeoTrust全球CA证书在您的机器上,建议由卡洛斯阿尔贝托洛佩兹佩雷斯:

wget --no-check-certificate -c https://www.geotrust.com/resources/root_certificates/certificates/GeoTrust_Global_CA.pem   \
&& mkdir /usr/local/share/ca-certificates/extra                                                                       \
&& mv GeoTrust_Global_CA.pem /usr/local/share/ca-certificates/extra/GeoTrust_Global_CA.crt                            \
&& update-ca-certificates

在亚马逊Linux (CentOS / Red Hat等)上,我做了以下工作来解决这个问题。首先复制cacert。Pem从http://curl.haxx.se/ca/cacert.pem下载,放在/etc/pki/ca-trust/source/anchors/目录下。执行update-ca-trust命令。

下面是来自https://serverfault.com/questions/394815/how-to-update-curl-ca-bundle-on-redhat的一句话

Curl https://curl.se/ca/cacert.pem -o /etc/pki/ca-trust/source/anchors/curl-cacert-updated。Pem && update-ca-trust

然而,由于curl被破坏,我实际上使用这个命令来下载cacert。pem文件。

Wget——no-check-certificate http://curl.haxx.se/ca/cacert.pem

执行update-ca-trust命令后,可以重新启动web服务器服务httpd restart (apache)或service nginx restart (nginx)。


简单地把两个更多的线在本地解决问题,这为我工作很好。

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);