Since last night, several of my scripts (on different servers) that use file_get_contents("https://...")
and curl
functions, stopped working.
Example request that fails:
file_get_contents("https://domain.tld/script.php");
Error:
PHP Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in /home/domain/public_html/script.php on line 19
I already "fixed" the problem using:
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
file_get_contents("https://domain.tld/path/script.php", false, stream_context_create($arrContextOptions));
The "fix" is far from ideal since I'm not verifying the authenticity of the connection, but until I understand the origin of the problem and how to prevent it from happening again, I'll be forced to use it.
Notes:
- PHP scripts with
Curl
also stopped working and the fix is similar:curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
; - The
SSL
certificate is issued byLet's Encrypt
and it was renewed last night ("not valid before 2020/12/24"); - All servers have the same timezone;
- I'm using
CentOS 7/Ubuntu 18
andVirtualmin
; - If I open
"https://domain.tld/script.php"
on Firefox/Chrome, no SSL warnings are shown and the certificate is valid; - I've tried to update the CA certificates (
yum install ca-certificates.noarch
), but the latest version is already installed;
I understand what's wrong, what I cannot figure out is why it started happening and how to fix it (the real fix).
Question:
How to fix and prevent it from happening again?