我试图用Stripe发送一个API请求,但得到错误消息:

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

这是我正在运行的代码:

public function chargeStripe()
{
    $stripe = new Stripe;
    $stripe = Stripe::make(env('STRIPE_PUBLIC_KEY'));

    $charge = $stripe->charges()->create([
        'amount'   => 2900,
        'customer' => Input::get('stripeEmail'),
        'currency' => 'EUR',
    ]);

    return Redirect::route('step1');
}

我在谷歌上搜索了很多,很多人建议我下载这个文件:cacert。Pem,把它放在某处,并在我的php.ini中引用它。这是我的php.ini中的部分:

curl.cainfo = "C:\Windows\cacert.pem"

然而,即使在重新启动服务器几次并更改路径之后,我仍然得到相同的错误消息。

我在Apache中启用了ssl_module,在我的php.ini中启用了php_curl。

我还尝试了这个修复:如何修复PHP CURL错误60 SSL

这表明我将这些行添加到我的cURL选项:

curl_setopt($process, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, true);

我在哪里添加选项到我的cURL?显然不是通过命令行,因为我的CLI没有找到命令“curl_setopt”


当前回答

我找到了一个适合我的解决办法。我把最新的版本降级到4.0,它是有效的。

在作曲家。添加“guzzlehttp/guzzle”:“~4.0”

希望它能帮助到别人

其他回答

狂饮版5

这个默认配置对我的工作很好。它将禁用https要求。

  $options = [
    'defaults' => ['verify' => false],
  ];
  new GuzzleClient($options);

在其他情况下,您要设置ca的路径,更改为:

['verify' => '/path/to/cacert.pem']

当我运行'var_dump(php_ini_loaded_file());' 我在页面上得到这个输出 “C: \开发\ bin \ apache \ apache2.4.33 \ bin \ php . ini”(长度= 50)'

为了让php加载我的证书文件,我必须在这个路径下编辑php.ini' C:\Development\bin\apache\apache2.4.33\bin\php.ini' 添加openssl.cafile="C:/Development/bin/php/php7.2.4/extras/ssl/cacert. exe "。pem”,我从https://curl.haxx.se/docs/caextract.html下载并放置了证书文件

我在Windows 10,使用drupal 8, wamp和php7.2.4

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

update-ca-certificates

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

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

I'm using Centos 7 with the free version of virtualmin. With Virtualmin you can create a wordpress website. There is functionality that will automatically update your ssl certificate for you. I noticed that /etc/httpd/conf/httpd.conf did not contain an entry for SSLCertificateChainFile. Which should be set to something like /home/websitename/ssl.combined. Updating that file accordingly and restarting apache fix this problem for me. I discovered my issue trying to install a jetpack plugin for wordpress. A search on the internet led me to realize that I didn't have SSL Configured. I followed Redhat's instructions on how to install a certificate. I hope this was useful to someone.

Wamp/Wordpress/windows用户请注意。我有这个问题几个小时了,甚至没有正确的答案是为我做的,因为我编辑了错误的php.ini文件,因为这个问题是回答XAMPP而不是WAMP用户,即使这个问题是为WAMP。

以下是我所做的:

Download the certificate bundle. Put it inside of C:\wamp64\bin\php\your php version\extras\ssl Inside of C:\wamp64\bin\apache\apache(version)\modules, make sure the file mod_ssl.so is there Inside of Apache directory C:\wamp64\bin\apache\apache2.4.27\conf, enable mod_ssl in httpd.conf Enable php_openssl.dll in php.ini. Be aware my problem was that I had two php.ini files and I need to do this in both of them. First one can be located inside of your WAMP taskbar icon here. And the other one is located in C:\wamp64\bin\php\php(Version) Find the location for both of the php.ini files and find the line curl.cainfo = and give it a path like this curl.cainfo = "C:\wamp64\bin\php\php(Version)\extras\ssl\cacert.pem" Now save the files and restart your server and you should be good to go