PHP - SSL证书错误:无法获得本地颁发者证书

问题描述 投票:145回答:14

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

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

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

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

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

并且当然从http://curl.haxx.se/docs/caextract.html下载到该位置的cacert.pem文件

但毕竟,重新启动XAMPP和Apache服务器但仍然得到相同的错误。

我真的不知道还有什么可以尝试的。

任何人都可以建议我还能尝试什么?

php ssl curl xampp mandrill
14个回答
297
投票

终于有了这个工作!

  1. 下载certificate bundle
  2. 把它放在某个地方。在我的情况下,这是c:\wamp\目录(如果你使用Wamp 64位,那么它是c:\wamp64\)。
  3. 启用Apache中的mod_sslphp_openssl.dll中的php.ini(在开头删除;取消注释它们)。但要小心,我的问题是我有两个php.ini文件,我需要在他们两个中这样做。一个是从WAMP任务栏图标中获得的一个,另一个是在我的情况下,在C:\wamp\bin\php\php5.5.12\
  4. php.ini文件中将这些行添加到您的证书中: curl.cainfo="C:/wamp/cacert.pem" openssl.cafile="C:/wamp/cacert.pem"
  5. 重启Wamp服务。

0
投票

如果上述解决方案都不适合您,请尝试将XAMPP安装更新为更新版本。

我用PHP 5.5.11运行XAMPP,同样的确切代码不起作用,我用php 5.6.28升级到XAMPP并且上面的解决方案有效。

另外,只更新PHP不起作用,或者似乎是该版本XAMPP上的apache和php设置的组合。

希望它可以帮助某人。


0
投票

我有这个问题的非常简单的解决方案。您可以在没有任何证书文件的情况下执

继续使用Laravel Root文件夹 - > Vender - > guzzlehttp - > guzzle - > src

打开Client.php

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

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

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

'verify'          => false,

所以在此之后它不会检查CURL请求的SSL证书...这个解决方案对我有用。经过多次研究后,我发现了这个解


0
投票

我试过这个有效

打开

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

并改变这一点

 $conf[CURLOPT_SSL_VERIFYHOST] = 2;
 `enter code here`$conf[CURLOPT_SSL_VERIFYPEER] = true;

对此

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

0
投票

我得到的错误如下:

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.

希望它可以帮助某人


-3
投票

为了guzzle你可以试试这个:

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

在guzzle / guzzle 3上测试。*


108
投票

免责声明:此代码使您的服务器不安全。

在第65行之后我在Mandrill.php文件中遇到了同样的问题,它说$ this-> ch = curl_init();

添加以下两行:

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

这解决了我的问题,并使用localhost发送电子邮件,但我建议不要在实时版本上使用它。在您的实时服务器上,代码应该没有此代码。


41
投票

谢谢@Mladen Janjetovic,

您的建议适用于安装了Ampps的mac。

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

致:/Applications/AMPPS/extra/etc/openssl/certs/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证书,this post上的步骤在Centos 7 / Vagrant / Chrome Browser上为我工作。


18
投票

当您查看http://curl.haxx.se/docs/caextract.html页面时,您会在大字母中注意到一个名为:

RSA-1024已删除

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

这些将与Mandrill合作。

禁用SSL是个坏主意。


10
投票

上述步骤虽然有用,但在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服务器,应该修复它(只需根据需要停止并启动服务)。

9
投票

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

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

7
投票

如果您无法访问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中指定的位置。


2
投票

详细说明服务器部署的上述答案。

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

应该为开发环境做好准备而不会在部署时危及服务器。


0
投票

在AppVeyor中构建我的应用程序时遇到了同样的问题。

  • 下载https://curl.haxx.se/ca/cacert.pemc:\php
  • 启用openssl echo extension=php_openssl.dll >> c:\php\php.ini
  • 找到certificateecho curl.cainfo=c:\php\cacert.pem >> c:\php\php.ini
© www.soinside.com 2019 - 2024. All rights reserved.