cURL error 60: SSL certificate (GuzzleHttp v6)

2020-06-03

この記事はPHP Advent Calendar 2018に参加しています。



cURL error 60 GuzzleHttp\Guzzle v6 (cURL)

・環境:win10 PHP7.1.1 guzzlehttp/guzzle(6.3.3)

リクエストしようとすると以下エラーが

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http: curl.haxx.se libcurl c libcurl errors.html)

 

原因

Win環境cURLでクライアント証明書が見つけられないために起こる問題のよう
 

解決方法

・クライアント証明書を指定して解決

ググると以下に解決方法が載ってました。
https://github.com/yabacon/paystack-php/wiki/cURL-error-60:-SSL-certificate-problem:-unable-to-get-local-issuer-certificate-(see-http:–curl.haxx.se-libcurl-c-libcurl-errors.html)
以下引用

To resolve the error, you need to define your CURL certificate authority information path

To do that,

1.Download the latest curl recognized certificates here: https://curl.haxx.se/ca/cacert.pem
2.Save the cacert.pem file in a reachable destination.
3.Then, in your php.ini file, scroll down to where you find [curl].
4.You should see the CURLOPT_CAINFO option commented out. Uncomment and point it to the cacert.pem file. You should have a line like this:

curl.cainfo = “certificate path\cacert.pem”

Save and close your php.ini. Restart your webserver and try your request again.
If you do not set the right location, you will get a CURL 77 error.
  1. https://curl.haxx.se/ca/cacert.pemから証明書をDLして保存
  2. php.iniに設定して再起動 Finish!
    これだけで完了です。
php.ini
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo ="ここに証明書のパスを指定"

 

 

・クライアント証明書を検証しないで解決

Guzzle側のオプションで「証明書の検証無し」を指定してやることでエラーがでなくなります。
指定方法もとても簡単です。
http://docs.guzzlephp.org/en/stable/request-options.html#verify

$config = ['base_uri' => 'https://hogehoge.com'];
$client = new GuzzleHttp\Client($config);
$res = $client->request('GET', '/', ['verify' => false]); //ここでオプション指定
return $res->getStatusCode();

//guzzlephp本家ドキュメント
http://docs.guzzlephp.org/en/stable/request-options.html#verify

https://github.com/yabacon/paystack-php/wiki/cURL-error-60:-SSL-certificate-problem:-unable-to-get-local-issuer-certificate-(see-http:–curl.haxx.se-libcurl-c-libcurl-errors.html)

https://qiita.com/mapyo/items/5307e1b36437600c2c34