LoginSignup
32
15

More than 5 years have passed since last update.

(現在は解決しました)PHPの外部への接続でSSLのエラーが出てしまう@KUSANAGI PHP7.2

Last updated at Posted at 2018-06-28

2018年7月4日に解消されました

KUSANAGIモジュール更新情報

はじめに

KUSANAGIを使っています。

一ヶ月ほど前(2018年5月)ごろからKUSANAGIをアップデートすると一部でエラーがでてしまうようになりました。

問題の経緯

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/test.php on line 4

Warning: file_get_contents(): Failed to enable crypto in /mnt/example.com/test.php on line 4

Warning: file_get_contents(https://example.com/test.jpg): failed to open stream: operation failed in /mnt/example/test.php on line 4

PHPで外部へ接続に行く際にエラーになってしまうようです。

解決方法

/etc/php7.d/php.iniopenssl.cafile=/etc/ssl/certs/ca-bundle.crtを追記すれば問題が回避できました。

/etc/php7.d/php.ini
(中略)
 ; be overridden on a per-stream basis via the "cafile" SSL stream context
 ; option.
openssl.cafile=/etc/ssl/certs/ca-bundle.crt

 ; If openssl.cafile is not specified or if the CA file is not found, the
 ; directory pointed to by openssl.capath is searched for a suitable
(中略)

問題の確認など

phpinfoを設置して、環境変数openssl.cafileが設定されているのか、居ないのかを確認します。

/home/kusanagi/example.com/DocumentRoot/phpinfo.php
<?php phpinfo();

アップデート後はopenssl.cafileの値が空欄になっていました。

上記の解決策を入れると/etc/ssl/certs/ca-bundle.crtが設定されています。

image.png

自分の場合はPHP7-FPMを使っていたので/etc/php7.d/php.iniが設定ファイルでした。
環境変数を読み出す対象となるファイルは確認が必要です。

image.png

特にKUSANAGIの場合にはいろんなphp.ini系のファイルがあるので注意が必要でした。

解決できなかったけどヒントになった情報

エラーメッセージでググると情報がたくさん出てきます。

$url = "https://xxxxxx";
$options['ssl']['verify_peer']=false;
$options['ssl']['verify_peer_name']=false;
$response = file_get_contents($url, false, stream_context_create($options));

開発環境で自己署名しているhttps環境において、file_get_contentsすると、
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL > routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in xxxxx

というエラーが表示されます。
証明書入れてくれよと思うのですが、導入できない時もあります。その場合は、optionを付与することで回避できます。

なのですが、cURLやfile_get_contents()の情報がでてくるのですが、PHPの根本から解決する情報がありませんでした。

GuzzleなどのcURLをラッピングしてしまうライブラリの場合、中のオプション設定が結構大変そうだったため、解決策を探していました。

うまく解決出来てよかったです。

32
15
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
32
15