php cURL 错误 60:SSL 证书 prblm:无法获得本地颁发者证书
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35638497/
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 prblm: unable to get local issuer certificate
提问by Sjors Hijgenaar
I want to collect a list of videos uploaded on a specific channel using the YouTube data API. However, before implementing online I am trying to get my code running on an offline environment (WAMPserver, PHP 5.5.12, Apache 2.4.9). I am using the following code:
我想收集使用 YouTube 数据 API 上传到特定频道的视频列表。但是,在在线实施之前,我试图让我的代码在离线环境(WAMPserver、PHP 5.5.12、Apache 2.4.9)上运行。我正在使用以下代码:
require_once 'google-api-php-client-2.0.0-RC5/vendor/autoload.php';
$client = new Google_Client();
$client->setApplicationName("SRC_Thor");
$client->setDeveloperKey("xxxxxxxxxxx");
$youtube = new Google_Service_YouTube($client);
$channelResponse = $youtube->channels->listChannels('contentDetails', []);
var_dump($channelResponse);
However it gives the following error:
但是它给出了以下错误:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate (see
http://curl.haxx.se/libcurl/c/libcurl-errors.html
)'
致命错误:未捕获的异常“GuzzleHttp\Exception\RequestException”,消息为“cURL 错误 60:SSL 证书问题:无法获得本地颁发者证书(请参阅
http://curl.haxx.se/libcurl/c/libcurl-errors.html
)”
I have tried adding the latest version of cacert.pem
as most topics on SO offer as a solution, however to no avail.
我曾尝试添加最新版本的cacert.pem
SO 提供的大多数主题作为解决方案,但无济于事。
回答by Phung D. An
If you are on Windows using Xampp, I am stealing a better answer from here, would be helpful if Google shows you this question first.
如果您使用 Xampp 在 Windows 上,我从这里窃取了一个更好的答案,如果谷歌首先向您展示这个问题会很有帮助。
Download and extract for cacert.pem here (a clean file format/data)
Put it in :
C:\xampp\php\extras\ssl\cacert.pem
Add this line to your php.ini
curl.cainfo = "C:\xampp\php\extras\ssl\cacert.pem"
restart your webserver/Apache
在此处下载并提取 cacert.pem(干净的文件格式/数据)
把它放进去 :
C:\xampp\php\extras\ssl\cacert.pem
将此行添加到您的 php.ini
curl.cainfo = "C:\xampp\php\extras\ssl\cacert.pem"
重新启动您的网络服务器/Apache
回答by Sjors Hijgenaar
Seeing I am using a local environment I can safely disable SSL, which i did using the following:
看到我使用的是本地环境,我可以安全地禁用 SSL,我使用以下方法:
$guzzleClient = new \GuzzleHttp\Client(array( 'curl' => array( CURLOPT_SSL_VERIFYPEER => false, ), ));
$client->setHttpClient($guzzleClient);
Where $client
is my Google_Client().
$client
我的 Google_Client()在哪里。
回答by lijinma
$guzzleClient = new \GuzzleHttp\Client(['verify' => false]);
Guzzle version 6
狂饮版本 6
You could refer to Guzzle Docs at
你可以参考 Guzzle Docs
http://docs.guzzlephp.org/en/latest/request-options.html#verify
http://docs.guzzlephp.org/en/latest/request-options.html#verify
回答by Abdalla Mohamed Aly Ibrahim
I work with xamps nothing of the above did work for me
我与 xamps 一起工作,上面没有对我有用
I tried this and it worked
我试过了,它奏效了
- open
vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php
- 打开
vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php
and change this
并改变这一点
$conf[CURLOPT_SSL_VERIFYHOST] = 2;
$conf[CURLOPT_SSL_VERIFYPEER] = true;
to this
对此
$conf[CURLOPT_SSL_VERIFYHOST] = 0;
$conf[CURLOPT_SSL_VERIFYPEER] = FALSE;
it's a temporary solution if you updated this file the changes will lost
这是一个临时解决方案,如果您更新此文件,更改将丢失
回答by walecloud
for the essence of development and testing, You have two options to a quick fix
对于开发和测试的本质,您有两个选项可以快速修复
- Use
- 用
$client = new GuzzleHttp\Client();
$request = $client->request('GET',$url, ['verify' => false]); //where $url is your http address
- follow @Pham Huy Anh answer's above then do this
- 按照上面的@Pham Huy Anh 回答然后执行此操作
$client = new GuzzleHttp\Client();
$request = $client->request('GET',$url, ['verify' => 'C:\xampp\php\extras\ssl\cacert.pem']);
Hope it helps someone.
希望它可以帮助某人。
回答by kimoduor
it also worked for me by downloading the cert from the link https://gist.github.com/VersatilityWerks/5719158/downloadthen save it in C:\xampp\php\extras\ssl then edit php.ini. To get Php.ini quickly see the figure below enter image description here
通过从链接https://gist.github.com/VersatilityWerks/5719158/download下载证书, 然后将其保存在 C:\xampp\php\extras\ssl 中,然后编辑 php.ini,它也对我有用。快速获取Php.ini见下图,在此 输入图片说明
Then STOP and reStart your apache again. it worked well !!!
然后停止并重新启动您的apache。它运作良好!!!
回答by Machavity
PCI-DSS 3.1 requires all SSL to only TLS 1.2 so a lot of providers are simply turning everything but TLS 1.2 off. I ran into this type of issue where CURL saw the failure to downgrade handshakes as a failure to verify the SSL certificate. Try finding where your code is doing the CURL call and add this line (be sure to replace $ch
with whatever CURL handle your code uses)
PCI-DSS 3.1 要求所有 SSL 仅支持 TLS 1.2,因此许多提供商只是关闭了除 TLS 1.2 之外的所有内容。我遇到了这种类型的问题,其中 CURL 将握手降级失败视为验证 SSL 证书失败。尝试找到您的代码在何处执行 CURL 调用并添加此行(确保替换$ch
为您的代码使用的任何 CURL 句柄)
curl_setopt($ch, CURLOPT_SSLVERSION, 6); // Force TLS 1.2
回答by abbas waranlu
$guzzleClient = new \GuzzleHttp\Client(['verify' => false]);