我在MacOSx El Capitan中运行PHP 5.6版作为XAMPP的一部分,在一些https
站点上出现错误。例如:https://www.google.com/
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
但在这些网站上没有返回SSL错误:
- GitHub
- 作曲家
- PayPal TLS测试
请先找到清单,我已经试过了,但没有任何效果。
首先尝试谷歌:
- SSL错误SSL3_GET_SERVER_CERTIFICATE:证书验证失败
- PHP-SSL证书错误:无法获取本地颁发者证书
- HTTPS和SSL3_GET_SERVER_CERTIFICATE:证书验证失败,CA正常
手动
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] =>
)
将此文件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 certificate problem: unable to get local issuer certificate"
附言:禁用对等验证是不可接受的。
在我的情况下,确保存在正确的cert.pem文件是不够的。您还需要使用date.timezone
键将php.ini中的时区设置为实际时区(在我的情况下,我将其设置为美国/洛杉矶)。否则,PHP将默认使用UTC,您的系统时钟将显示为关闭。这为我解决了Mac OS X El Capitan(10.11.2)上的问题。