LoginSignup
33
26

More than 5 years have passed since last update.

Windows版PHPのcurlの証明書

Last updated at Posted at 2014-06-24

Windows版のPHPでcurlを使った時に、CA証明書がないというエラーが発生する場合がある。

test.php
<?php
$ch = curl_init("https://www.google.co.jp");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_exec($ch);
curl_close($ch);
> php test.php
* Adding handle: conn: 0x3015700
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x3015700) send_pipe: 1, recv_pipe: 0
* About to connect() to www.google.co.jp port 443 (#0)
*   Trying 74.125.235.87...
* Connected to www.google.co.jp (74.125.235.87) port 443 (#0)
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0

あと、composerで警告がでることもある。

※2016/8/3現在リリースされているcomposerには証明書が同梱されているようです(https://github.com/composer/ca-bundle)

  - Installing pimple/pimple (v1.1.1)
Failed to download pimple/pimple from dist: You must enable the openssl extension to download files via https
Now trying to download from source
  - Installing pimple/pimple (v1.1.1)
    Cloning 2019c145fe393923f3441b23f29bbdfaa5c58c4d

解決方法は色々あるがその1つ。

Windowsのコマンドラインからcurlが動く環境であれば、バイナリと同じ場所に証明書が置いてある可能性がある。

自分の環境では、Git for Windowsにcurlが同梱されていたので、
C:\Program Files (x86)\Git\bin\curl-ca-bundle.crt
があった。

これをPHPのcurlで使うには、php.iniでcurl.cainfoを設定する。

php.ini
curl.cainfo="c:\Program Files (x86)\Git\bin\curl-ca-bundle.crt" (無くなってます)
curl.cainfo="c:\Program Files\Git\usr\ssl\certs\ca-bundle.crt"
33
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
26