无法弄清楚可能是什么:
在我的本地环境中,将我的 OSX 更新到最新版本的 Yosemite 后,出现此错误:
CurlException: [curl] 51: SSL: certificate verification failed (result: 5) [url]
我正在使用 Symfony2,因此它与 PHP 相关。我试图重新安装 openssl 但没有任何反应。
有什么建议吗?
最佳答案
查看出现此错误的任何域的证书链。对我来说是 googleapis.com
openssl s_client -host www.googleapis.com -port 443
你会得到这样的结果:
CONNECTED(00000005)
depth=1 C = US, O = Google Trust Services, CN = Google Internet Authority G3
verify error:num=20:unable to get local issuer certificate
---
Certificate chain
0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.googleapis.com
i:/C=US/O=Google Trust Services/CN=Google Internet Authority G3
1 s:/C=US/O=Google Trust Services/CN=Google Internet Authority G3
i:/OU=GlobalSign Root CA - R2/O=GlobalSign/CN=GlobalSign
注意:我在解决问题后捕获了这个。此外,您的链输出看起来会有所不同。
然后您需要查看在apache 下运行的php 中允许的证书。在页面中运行 phpinfo()。
<?php echo phpinfo();
然后通过在页面中搜索 openssl.cafile
来查找从页面输出加载的证书文件:
openssl.cafile openssl.cafile /usr/local/php5/ssl/certs/cacert.pem
这是您需要通过向其添加正确的证书来修复的文件。
sudo nano /usr/local/php5/ssl/certs/cacert.pem
您基本上需要将正确的证书“签名”附加到此文件的末尾。
你可以在这里找到其中的一些:
它们看起来像这样:
(注意:这是一张图片,因此人们不会简单地从 stackoverflow 复制/粘贴证书)
如果您需要将 .crt 转换为 pem,则需要执行以下操作:
openssl x509 -inform DER -outform PEM -in GIAG2.crt -out GIA2.pem
一旦正确的证书在此文件中,重新启动 apache 并进行测试。
关于php - curl 异常 : [curl] 51: SSL: certificate verification failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25424024/