SSL:can't load CA certificate file cacert.pem

用自己Mac做服务器推送消息的时候,在终端运行php文件报错:

Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /Users/rednow/my work/developer/pushMe.php on line 21

Warning: stream_socket_client(): Failed to enable crypto in /Users/rednow/my work/developer/pushMe.php on line 21

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/rednow/my work/developer/pushMe.php on line 21
Failed to connect: 0

在stackoverflow找了半天,发现应该是需要替换cacert.pem这个文件,好像是和https被禁掉有关:
http://stackoverflow.com/questions/3777075/ssl-certificate-rejected-trying-to-access-github-over-https-behind-firewall

后来发现pod update 都不能更新了,报错:


SSL:can't load CA certificate file cacert.pem_第1张图片
F6AF630D-47A5-48C6-86C7-3D0678B68588.png

"SSL:can't load CA certificate file cacert.pem"

一开始以为只是openssl的证书过期,但是按照大神们的套路更换后,还是没有好,大神帖子:
https://ruby-china.org/topics/24840

具体的步骤是:
1,先检查路径是否正确:

ruby -e "require 'openssl'; puts OpenSSL::X509::DEFAULT_CERT_FILE"

如果是homebrew安装的默认路径是:

/usr/local/etc/openssl/cert.pem

2,路径没有问题的话开始更新证书:

wget -c http://curl.haxx.se/ca/cacert.pem
mv cacert.pem /usr/local/etc/openssl/cert.pem 

还有方法B,可以使用RVM来更新证书:

rvm osx-ssl-certs status all
 rvm osx-ssl-certs update all
CB71972D-42BD-482E-85C1-46F0B97B0CF5.png

好的,我满心欢喜以为这样就搞定了,却发现始终还是报那个错误。
之后在网上大海捞针般的搜索了两天,我突然意识到,有一个答案我一开始就找到了,却没有引起重视:

SSL:can't load CA certificate file cacert.pem_第2张图片
4B5C3686-0A4F-4ECC-81B4-4B838D6F1FEE.png

https://github.com/Homebrew/legacy-homebrew/issues/44636
我虽然曾尝试过这个方法,却修改错了文件:git在mac上的配置文件应该是~/.gitconfig。(但是不懂为什么~/.git下,还有一些地方也有配置文件,有大神知道吗?)
于是我打开隐藏文件:

SSL:can't load CA certificate file cacert.pem_第3张图片
333D50C4-9A2C-4C0F-8041-124C399B6C24.png

修改之:

SSL:can't load CA certificate file cacert.pem_第4张图片
0E61084F-017A-4FA7-9ED2-60D6F67A6C38.png

,问题搞定!

你可能感兴趣的:(SSL:can't load CA certificate file cacert.pem)