我在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服务器,但仍然得到相同的错误。

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

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


当前回答

我在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设置的组合。

希望它能帮助到别人。

终于让这个工作了!

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.

如果你不能访问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未与链证书一起安装时,就会出现此问题。如果您的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