php cURL 错误 60:Laravel 5.4 中的 SSL 证书
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42094842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cURL error 60: SSL certificate in Laravel 5.4
提问by Yasmin French
Full Error
完全错误
RequestException in CurlFactory.php line 187: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
RequestException in CurlFactory.php line 187: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Scenario
设想
Before anyone points me to these two laracasts answers: https://laracasts.com/discuss/channels/general-discussion/curl-error-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate
在有人指出我这两个 laracasts 答案之前:https://laracasts.com/discuss/channels/general-discussion/curl-error-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate
I've already looked at them and thats why im here,
我已经看过他们了,这就是为什么我在这里,
The problem i have is that i now have the cacert.pem file BUT it doesn't make sense where to put it, the answers indicate to place the file in my xampp directory and change my php.ini
file but im not using xampp for anything, im using laravel's artisan server to run my project. If xampp is not in use then where do i place this file & more so why would an accepted answer be to place it in my xampp directory i dont understand
我遇到的问题是我现在有 cacert.pem 文件,但是把它放在哪里没有意义,答案表明将文件放在我的 xampp 目录中并更改我的php.ini
文件,但我没有使用 xampp 做任何事情,我使用 laravel 的 artisan 服务器来运行我的项目。如果 xampp 没有被使用,那么我该把这个文件放在哪里?
My Exact Question
我的确切问题
Where do i place the cacert.pem
file to stop this error in laravel 5.4?
cacert.pem
在laravel 5.4中,我在哪里放置文件来阻止这个错误?
回答by kjdion84
Do not evermodify files in the vendor/
folder. Ever. They can and will be overwritten on the next composer update you run.
永远不要修改文件vendor/
夹中的文件。曾经。它们可以并且将在您运行的下一次 Composer 更新时被覆盖。
Here is my Solution for WampServer
这是我的 WampServer 解决方案
I am using PHP 7.1.9 for my WampServer, so change 7.1.9
in the example below to the version number you are currently using.
我的 WampServer 使用的是 PHP 7.1.9,因此7.1.9
在下面的示例中更改为您当前使用的版本号。
- Download this file: http://curl.haxx.se/ca/cacert.pem
- Place this file in the
C:\wamp64\bin\php\php7.1.9
folder - Open
php.ini
and find this line:
- 下载此文件:http: //curl.haxx.se/ca/cacert.pem
- 将此文件放在
C:\wamp64\bin\php\php7.1.9
文件夹中 - 打开
php.ini
并找到这一行:
;curl.cainfo
;curl.cainfo
Change it to:
将其更改为:
curl.cainfo = "C:\wamp64\bin\php\php7.1.9\cacert.pem"
curl.cainfo = "C:\wamp64\bin\php\php7.1.9\cacert.pem"
Make sure you remove the semicolon at the beginning of the line.
确保删除该行开头的分号。
Save changes to php.ini
, restart WampServer, and you're good to go!
将更改保存到php.ini
,重新启动 WampServer,您就可以开始了!
回答by Yasmin French
This was stressfull to figure out but here is the exact answer for people using laravel and have this problem.
弄清楚这点很紧张,但这是使用 laravel 并遇到此问题的人的确切答案。
My exact application versions are...
我的确切应用程序版本是...
Laravel: 5.4
Guzzlehttp: 6.2
Laravel Socialite: 3.0
Laravel:5.4
狂饮http:6.2
Laravel 社交名媛:3.0
Download a fresh copy of this curl certificate from this link: https://gist.github.com/VersatilityWerks/5719158/download
从此链接下载此 curl 证书的新副本:https: //gist.github.com/VersatilityWerks/5719158/download
Save the file in this path starting from the base root of your laravel application vendor/guzzlehttp/guzzle/src/cacert.pem
将文件保存在此路径中,从 Laravel 应用程序的根目录开始 vendor/guzzlehttp/guzzle/src/cacert.pem
next in that same directory open up RequestOptions.php
and scroll down to the constant called CERT
and change it to this const CERT = 'cacert.pem';
and this should fix it all.
next 在同一目录中打开RequestOptions.php
并向下滚动到被调用的常量CERT
并将其更改为 this const CERT = 'cacert.pem';
,这应该可以解决所有问题。
EDIT
编辑
As people are pointing out you should never edit the vendor folder, this was just a quick fix for an application I was building in my spare time. It wasn't anything majorly important like an application for my company or anything, use this method at your own risk! Please check out the other answers if you need something more concrete.
正如人们指出的那样,您永远不应该编辑供应商文件夹,这只是我在业余时间构建的应用程序的快速修复。这不是我公司的应用程序或其他任何重要的事情,请自担风险使用此方法!如果您需要更具体的内容,请查看其他答案。
回答by Jeffrey
A quick solution but insecure (not recommended).
一个快速但不安全的解决方案(不推荐)。
Using cURL:
使用卷曲:
Set CURLOPT_SSL_VERIYPEER to false
Using Guzzle: Set verify to false, for example
使用Guzzle:例如将 verify 设置为 false
$client->request('GET', 'https://somewebsite.com', ['verify' => false]);
回答by Hamza Rashid
- Solution suggested by some users to make changes to
\vendor\guzzlehttp\guzzle\src\Client.php
file is the worst advice, as manual changes made to vendor folder are overwritten if you runcomposer update
command. - Solution suggested by Jeffreyis a dirty, shorthand fix but not recommended in production applications.
- Solution suggested by kjdion84is perfect if you have access to
php.ini
file on web server. In case you are using Shared Hosting, it may not be possible to editphp.ini
file.
- 一些用户建议更改
\vendor\guzzlehttp\guzzle\src\Client.php
文件的解决方案是最糟糕的建议,因为如果您运行composer update
命令,对供应商文件夹所做的手动更改将被覆盖。 - Jeffrey建议的解决方案是一种肮脏的速记修复,但不建议在生产应用程序中使用。
- 如果您有权访问Web 服务器上的文件,kjdion84建议的解决方案是完美的
php.ini
。如果您使用的是共享主机,则可能无法编辑php.ini
文件。
When you don't have access to php.ini
file (e.g. Shared Hosting)
当您无权访问php.ini
文件时(例如共享主机)
- Download this file: http://curl.haxx.se/ca/cacert.pem
- Place this file in the root folder of your Laravel project.
- Add
verify
key toGuzzleHttp\Client
constructor with its value as path tocacert.pem
file.
- 下载此文件:http: //curl.haxx.se/ca/cacert.pem
- 将此文件放在 Laravel 项目的根文件夹中。
- 将
verify
键添加到GuzzleHttp\Client
构造函数,其值作为cacert.pem
文件路径。
With Laravel 5.7 and GuzzleHttp 6.0
使用 Laravel 5.7 和 GuzzleHttp 6.0
// https://example.com/v1/current.json?key1=value1&key2=value2
$guzzleClient = new GuzzleHttp\Client([
'base_uri' => 'https://example.com',
'verify' => base_path('cacert.pem'),
]);
$response = $guzzleClient->get('v1/current.json', [
'query' => [
'key1' => 'value1',
'key2' => 'value2',
]
]);
$response = json_decode($response->getBody()->getContents(), true);
回答by omarjebari
I had this problem while running Valet and attempting to make an api from one site in valet to another. Note that i'm working in OSX. I found the solution here: https://github.com/laravel/valet/issues/460In short you have to copy the valet pem to the system CA bundle. Just run this:
我在运行 Valet 并尝试从一个站点到另一个站点制作 api 时遇到了这个问题。请注意,我在 OSX 中工作。我在这里找到了解决方案:https: //github.com/laravel/valet/issues/460总之,您必须将代客 pem 复制到系统 CA 包。只需运行这个:
cp /usr/local/etc/openssl/cert.pem /usr/local/etc/openssl/cert.pem.bak && cat ~/.config/valet/CA/LaravelValetCASelfSigned.pem >> /usr/local/etc/openssl/cert.pem
回答by Doshibu
Another one recently asked for the same problem and it's seems my answer was the solution for him. Here was the post I mention : URL Post
另一个人最近问了同样的问题,看来我的回答是他的解决方案。这是我提到的帖子:URL Post
That's what I said :
这就是我所说的 :
I'll be fully honest, I don't know anything about Laravel. But I had the same problem, so as many other, on Symfony. And so as you I tried many things without success.
Finally, this solution worked for me : URL solution
It indicates that instead of a certificate problem, it could came from a environnement non-compatibility. I used XAMPP instead of WAMP and it worked.
老实说,我对 Laravel 一无所知。但是我在 Symfony 上遇到了同样的问题,和其他许多问题一样。所以和你一样,我尝试了很多事情都没有成功。
最后,这个解决方案对我有用: URL 解决方案
它表明不是证书问题,而是环境不兼容。我使用 XAMPP 而不是 WAMP 并且它起作用了。
回答by Sruthikeralan
for Laravel: The 5 steps below will be helpful
对于 Laravel:以下 5 个步骤会有所帮助
- update version to
Guzzlehttp: 5.2
- find the file under
\vendor\guzzlehttp\guzzle\src\Client.php
edit default settings to
protected function getDefaultOptions() { $settings = [ 'allow_redirects' => true, 'exceptions' => true, 'decode_content' => true, 'verify' => getcwd() .'/vendor/guzzlehttp/guzzle/src/cacert.pem' ]; }
download latest file cacert.pem from
http://curl.haxx.se/ca/cacert.pem
and place under/vendor/guzzlehttp/guzzle/src/
- 将版本更新为
Guzzlehttp: 5.2
- 找到下面的文件
\vendor\guzzlehttp\guzzle\src\Client.php
将默认设置编辑为
protected function getDefaultOptions() { $settings = [ 'allow_redirects' => true, 'exceptions' => true, 'decode_content' => true, 'verify' => getcwd() .'/vendor/guzzlehttp/guzzle/src/ cacert.pem']; }
下载最新文件 cacert.pem
http://curl.haxx.se/ca/cacert.pem
并将其放在下面/vendor/guzzlehttp/guzzle/src/