我试图用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”


当前回答

这可能是一个边缘情况,但在我的情况下,问题不是客户端配置(我已经有卷曲。在php.ini中配置了cfo),而不是远程服务器没有正确配置:

它没有在链中发送任何中间证书。没有错误浏览网站使用Chrome,但与PHP我得到以下错误。

卷曲度错误60

在远程web服务器配置中包含中级证书后,它工作了。

您可以使用此站点检查服务器的SSL配置:

https://whatsmychaincert.com/

其他回答

当我运行'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

如何解决这个问题:

下载并提取cacert。请参考https://curl.se/docs/caextract.html上的说明 将它保存在文件系统的某个地方(例如,XAMPP用户可能使用C:\ XAMPP \php\extras\ssl\cacert.pem) 在你的php.ini中,把这个文件的位置放在[curl]部分(把它放在[openssl]部分也是一个好主意):

[curl]
curl.cainfo = "C:\xampp\php\extras\ssl\cacert.pem"

[openssl]
openssl.cafile = "C:\xampp\php\extras\ssl\cacert.pem"

重启您的web服务器(例如Apache)和PHP FPM服务器(如果适用)

(参考:https://laracasts.com/discuss/channels/general-discussion/curl-error-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate)

如果你在Guzzle中使用PHP 5.6, Guzzle已经切换到使用PHP库自动检测证书,而不是它的进程(参考)。PHP在这里概述了这些变化。

找出PHP/Guzzle在哪里寻找证书

你可以使用下面的PHP命令转储PHP正在寻找的地方:

 var_dump(openssl_get_cert_locations());

获取证书包

对于OS X测试,可以先使用homebrew安装openssl,再使用openssl.cafile=/usr/local/etc/openssl/cert。在您的php.ini或Zend服务器设置(在OpenSSL下)中的pem。

证书包也可以从curl/Mozilla的curl网站上获得:https://curl.haxx.se/docs/caextract.html

告诉PHP证书在哪里

一旦你有了一个bundle,要么把它放在PHP已经在寻找的地方(上面你已经发现了),要么更新openssl。php.ini中的Cafile。(一般在Unix上是/etc/php.ini或/etc/php/7.0/cli/php.ini或/etc/php/php.ini)

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.

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

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

希望它能帮助到别人