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


当前回答

cartalyst/stripe使用的Guzzle,将执行以下操作来查找合适的证书存档来检查服务器证书:

Check if openssl.cafile is set in your php.ini file. Check if curl.cainfo is set in your php.ini file. Check if /etc/pki/tls/certs/ca-bundle.crt exists (Red Hat, CentOS, Fedora; provided by the ca-certificates package) Check if /etc/ssl/certs/ca-certificates.crt exists (Ubuntu, Debian; provided by the ca-certificates package) Check if /usr/local/share/certs/ca-root-nss.crt exists (FreeBSD; provided by the ca_root_nss package) Check if /usr/local/etc/openssl/cert.pem (OS X; provided by homebrew) Check if C:\windows\system32\curl-ca-bundle.crt exists (Windows) Check if C:\windows\curl-ca-bundle.crt exists (Windows)

你需要通过一个简单的测试来确保前两个设置的值是正确定义的:

echo "openssl.cafile: ", ini_get('openssl.cafile'), "\n";
echo "curl.cainfo: ", ini_get('curl.cainfo'), "\n";

或者,尝试将文件写入#7或#8所指示的位置。

其他回答

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.

我所做的是使用var_dump(openssl_get_cert_locations());死;在任何PHP脚本中,它给了我关于本地PHP正在使用的默认值的信息:

array (size=8)
  'default_cert_file' => string 'c:/openssl-1.0.1c/ssl/cert.pem' (length=30)
  'default_cert_file_env' => string 'SSL_CERT_FILE' (length=13)
  'default_cert_dir' => string 'c:/openssl-1.0.1c/ssl/certs' (length=27)
  'default_cert_dir_env' => string 'SSL_CERT_DIR' (length=12)
  'default_private_dir' => string 'c:/openssl-1.0.1c/ssl/private' (length=29)
  'default_default_cert_area' => string 'c:/openssl-1.0.1c/ssl' (length=21)
  'ini_cafile' => string 'E:\xampp\php\extras\ssl\cacert.pem' (length=34)
  'ini_capath' => string '' (length=0)

正如你所注意到的,我已经设置了ini_cafile或ini选项curl. cannfo。但在我的情况下,curl将尝试使用“default_cert_file”,它并不存在。

我将文件从https://curl.haxx.se/ca/cacert.pem复制到“default_cert_file”的位置(c:/openssl-1.0.1c/ssl/cert.pem),我能够让它工作。

这是我唯一的解决办法。

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

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

希望它能帮助到别人

当你在使用Windows时,我认为你的路径分隔符是'\'(在Linux上是'/')。 尝试使用常量DIRECTORY_SEPARATOR。您的代码将更易于移植。

Try:

curl_setopt($process, CURLOPT_CAINFO, dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cacert.pem');

EDIT:并写入完整路径。我有一些相对路径的问题(也许curl是从另一个基目录执行的?)

如何解决这个问题:

下载并提取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)