LoginSignup
1

More than 5 years have passed since last update.

PHPでfopenとかcURLとかでSSL関連のエラーが発生して困ってます

Last updated at Posted at 2018-05-18

はじめに

PHP(NGINX + PHP-FPM)から外のサーバにHTTPS通信をしたときにエラーが出るようになりました。

  • 相手方の証明書に問題はない
  • 複数のサーバ(クラウドサーバ、VPS)で発生

という状況でした。

事例1

WordPressのJetpackからTwitterへの自動投稿でエラーが出るようになっていました。

Screen_Shot_2018-05-18_at_15_32_02.jpg

事例2

こちらもJetpackですが、HTTPSの通信でエラーが発生していました。

Screen Shot 2018-05-18 at 15.34.28.png

事例3

PHPのcURL系(この場合はSimpleXML)でエラー。

Warning: simplexml_load_file(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mnt/example.com/wp/wp-content/themes/example/functions.php on line 506

Warning: simplexml_load_file(): Failed to enable crypto in /mnt/example.com/wp/DocumentRoot/wp-content/themes/example/functions.php on line 506

事例4

file_get_contents(fopen)で外部を開いた時にエラー。

2018/05/09 15:41:47 [error] 9268#0: *1641694 FastCGI sent in stderr: "PHP message: PHP 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/wp-content/themes/example/functions.php on line 468
test.php
var_dump('hoge');
ini_set('display_errors', true);
echo file_get_contents('https://example.com/hoge.jpg');
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

経過

同じテストコードを使ってPHP7.2系で発生していて、PHP7.0だと発生していません。
バージョンによるデフォルトのコンフィグが原因かも…。

PHP7.0系のOpenSSL
Screen Shot 2018-05-18 at 16.36.23.png

PHP7.2.5のOpenSSL
Screen Shot 2018-05-18 at 16.36.26.png

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
What you can do with signing up
1