file_get_contentsでSSL operation failedというエラー

投稿者: | 2021年11月29日

phpでfile_get_contentsを使っていたところ、下記のようなエラーが発生。

file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed {"exception":"[object] (ErrorException(code: 0): file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed at ...)

調べてみると、どうもPHPが動作するサーバーが持っているルートCA証明書の一覧が古い模様。そこで下記のコマンドを実行して更新。

yum update ca-certificates

これでエラーは解消されました。