首页 文章

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

提问于
浏览
123

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

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

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

11 回答

  • 250

    我找到了没有任何必要认证的新解决方案来调用curl只添加两行代码 .

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

    谢谢@Mladen Janjetovic,

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

    Copied: http://curl.haxx.se/ca/cacert.pem

    To: /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 上为我工作 .

  • -3

    终于有了这个工作!

    • 下载certificate bundle .

    • 把它放在某个地方 . 在我的情况下,那是 c:\wamp\ 目录(如果你使用Wamp 64位,那么它是 c:\wamp64\ ) .

    • 在Apache中启用 mod_ssl ,在 php.ini 中启用 php_openssl.dll (通过在开头删除 ; 取消注释它们) . 但要小心,我的问题是我有两个 php.ini 文件,我需要在两个文件中执行此操作 . 一个是从WAMP任务栏图标中获得的一个,另一个是在我的情况下,在 C:\wamp\bin\php\php5.5.12\

    • php.ini 文件中将这些行添加到您的证书中:

    curl.cainfo="C:/wamp/cacert.pem"
    openssl.cafile="C:/wamp/cacert.pem"
    
    • 重启Wamp服务 .
  • 0

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

    • 下载https://curl.haxx.se/ca/cacert.pemc:\php

    • 启用openssl echo extension=php_openssl.dll >> c:\php\php.ini

    • 找到证书 echo curl.cainfo=c:\php\cacert.pem >> c:\php\php.ini

  • 0

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

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

    添加以下两行:

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

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

  • 5

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

  • 36

    当您查看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

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

  • 6

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

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

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

    希望它可以帮到某人 .

  • 1

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

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

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

  • 90

    为了guzzle你可以试试这个:

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

    在guzzle / guzzle 3上测试 . *

相关问题