[英]php SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
I'm running PHP Version 5.6 as part of XAMPP in MacOSx El Capitan and having error on few https
sites. 我在MacOSx El Capitan中运行PHP版本5.6作为XAMPP的一部分,并且在几个
https
站点上出错。 eg: https://www.google.com/
例如:
https://www.google.com/
: 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
But no SSL error returned on these sites: 但是这些网站上没有返回SSL错误:
Please find the list first what i've tried so far but nothing works. 请先找到我迄今为止尝试过的清单,但没有任何效果。
Tried Google first: 首先尝试谷歌:
1. Updated cert.pem file 1.更新了cert.pem文件
php -r 'print_r(openssl_get_cert_locations());'
and result was. 结果是。
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] =>
)
Saved this file cacert.pem in /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
在
/Applications/XAMPP/xamppfiles/share/openssl/cert.pem
保存此文件cacert.pem
Updated php.ini
with following 更新了
php.ini
以下内容
openssl.cafile = /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
curl.cainfo = /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
Restarted Apache but no succes. 重启Apache但没有成功。 Tried to read pem file (no error returned)
试图读取pem文件(没有返回错误)
echo file_get_contents("/Applications/XAMPP/xamppfiles/share/openssl/cert.pem");
Test Case 测试用例
It works fine on github.com
getcomposer.org
paypal.com
but not on google.com
(google.com works as well on my windows system) 它在
github.com
getcomposer.org
paypal.com
上github.com
getcomposer.org
但在google.com
上github.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));'
Result: PayPal_Connection_OKbool(true)
结果:
PayPal_Connection_OKbool(true)
But on google.com
但是在
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));'
Result: string(63) "SSL certificate problem: unable to get local issuer certificate"
结果:
string(63) "SSL certificate problem: unable to get local issuer certificate"
PS: Disabling peer verification won't be acceptable. PS:禁用同行验证是不可接受的。
In my case, making sure that the correct cert.pem file exists was not sufficient. 在我的例子中,确保存在正确的cert.pem文件是不够的。 You need to also set your time zone in your php.ini to your actual time zone using the
date.timezone
key (in my case, I set it to America/Los Angeles). 您还需要使用
date.timezone
键将php.ini中的时区设置为您的实际时区(在我的情况下,我将其设置为America / Los Angeles)。 Otherwise, PHP will default to using UTC and your system clock will appear to be off. 否则,PHP将默认使用UTC,您的系统时钟将显示为关闭。 This solved the issue for me on Mac OS X El Capitan (10.11.2).
这解决了我在Mac OS X El Capitan上的问题(10.11.2)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.