我在 MacOSx El Capitan 中作为 XAMPP 的一部分运行 PHP 版本 5.6,并且在少数 https
站点上出现错误。例如:https://www.google.com/
file_get_contents():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败
但是这些站点没有返回 SSL 错误:
请先找到我到目前为止尝试过但没有任何效果的列表。
首先尝试了 Google:
- SSL error SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
- PHP - SSL certificate error: unable to get local issuer certificate
- HTTPS and SSL3_GET_SERVER_CERTIFICATE:certificate verify failed, CA is OK
手册
<强>1。更新的 cert.pem 文件
php -r 'print_r(openssl_get_cert_locations());'
结果是。
Array
(
[default_cert_file] => /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
[default_cert_file_env] => SSL_CERT_FILE
[default_cert_dir] => /Applications/XAMPP/xamppfiles/share/openssl/certs
[default_cert_dir_env] => SSL_CERT_DIR
[default_private_dir] => /Applications/XAMPP/xamppfiles/share/openssl/private
[default_default_cert_area] => /Applications/XAMPP/xamppfiles/share/openssl
[ini_cafile] => /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
[ini_capath] =>
)
已保存 this file cacert.pem在 /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
使用以下内容更新了 php.ini
openssl.cafile = /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
curl.cainfo = /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
重新启动 Apache 但没有成功。尝试读取 pem 文件(未返回错误)
echo file_get_contents("/Applications/XAMPP/xamppfiles/share/openssl/cert.pem");
测试用例
它在 github.com
getcomposer.org
paypal.com
上运行正常,但在 google.com
上运行不正常(google.com 在我的 Windows 系统上也能正常工作)
php -r '$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://tlstest.paypal.com/"); var_dump(curl_exec($ch)); var_dump(curl_error($ch));'
结果:PayPal_Connection_OKbool(true)
但是在 google.com
php -r '$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.google.com/"); var_dump(curl_exec($ch)); var_dump(curl_error($ch));'
结果:string(63) "SSL 证书问题:无法获取本地颁发者证书"
附言:禁用同行验证是 Not Acceptable 。
最佳答案
在我的例子中,确保存在正确的 cert.pem 文件是不够的。您还需要使用 date.timezone
键将 php.ini 中的时区设置为您的实际时区(在我的例子中,我将其设置为美国/洛杉矶)。否则,PHP 将默认使用 UTC,您的系统时钟将显示为已关闭。这为我解决了 Mac OS X El Capitan (10.11.2) 上的问题。
关于PHP SSL3_GET_SERVER_CERTIFICATE :certificate verify failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36477062/