【问题标题】:SSL certificate error unable to get local issuer certificateSSL 证书错误无法获取本地颁发者证书
【发布时间】:2015-03-18 01:04:14
【问题描述】:

此错误仅出现在我的在线网络服务器上。我正在使用更新的 cacert.pem 并在我的本地主机服务器的 php.ini 文件中引用它。

我的问题是如何在典型的 Web 服务器上完成此操作? (我的意思是通过php.ini 引用cacert.pem

或者,有没有一种方法可以在我的函数或我正在使用的通过 composer 安装的 Mailchimps API 函数中定义它?

我目前的功能:

bootstrap.php
require_once __DIR__ . '\..\..\lib\Cake\Network\Http\HttpSocket.php';

控制器:

//////////////////////////MAILCHIMP///////////////////////
                $Socket = new HttpSocket(array('ssl_cafile' => CAKE . 'Config' . DS . 'cacert.pem',         ));
                $api_key = "xxxxxxxxxxxxxxxxxxxxxxxx";
                $list_id = "xxxxxxxxx";

                $merge_vars = array('FNAME'=>$this->request->data['Subscriber']['first_name'], 'LNAME'=>$this->request->data['Subscriber']['last_name']);

                $Mailchimp = new Mailchimp( $api_key );
                $Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
                $subscriber = $Mailchimp_Lists->subscribe($list_id, array('email' => $this->request->data['Subscriber']['email']), $merge_vars);
/////////////////////////////////////////////////////////////

【问题讨论】:

标签: php cakephp ssl mailchimp


【解决方案1】:

与一些朋友交谈后,我发现我的 Web 服务器主机运行 cPanel,它有一个简单的 SSL 证书安装程序。

我无法评论 Rasclatt 提供的其他答案,因为我没有尝试过。不过听起来很全面。

对于遇到此问题的用户 - 检查您的主机是否正在运行 cPanel 软件 - 只需点击几下即可。

【讨论】:

    【解决方案2】:

    请注意,这仅对 PHP >= 5.6.0 有效,并且会自动运行

    如果您无权修改服务器上的php.ini 文件,您可以在代码中使用ini_set('openssl.cafile', '/path/to/cacert'); (http://php.net/manual/en/context.ssl.php#context.ssl.cafile)(您可以在此处阅读更多信息:https://wiki.php.net/rfc/tls-peer-verification)。

    如果您需要检查您的cafile当前设置的位置,您可以使用openssl_get_cert_locations

    如果您使用的是 PHP

    您可能需要扩展 Mailchimp 类:

    class MailchimpWithTLS extends Mailchimp {
        public function __construct($apikey=null, $opts=array()) {
            // Build the Mailchimp object normally
            parent::__construct($apikey=null, $opts);
    
            // Set the peer verification cURL fields
            curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 1);
            curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($this->ch, CURLOPT_CAINFO, $opts['cafile']);
        }
    }
    

    并通过将cafile位置作为选项传递给构造函数来初始化它:

    $Mailchimp = new MailchimpWithTLS( $api_key , array('cafile' => CAKE . 'Config' . DS . 'cacert.pem'));
    

    【讨论】:

      猜你喜欢
      • 2011-12-26
      • 2016-07-06
      • 2018-06-11
      • 2017-07-19
      相关资源
      最近更新 更多