php - curl 异常 : [curl] 51: SSL: certificate verification failed

标签 php symfony curl ssl

无法弄清楚可能是什么:

在我的本地环境中,将我的 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

您基本上需要将正确的证书“签名”附加到此文件的末尾。

你可以在这里找到其中的一些:

它们看起来像这样:

example certificate image

(注意:这是一张图片,因此人们不会简单地从 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/

相关文章:

Symfony3 文档 WSSE 失败 "Cannot replace arguments if none have been configured yet"

symfony - 具有多个ID的findBy

php - Paypal - Zend_Http_Client_Adapter_Curl - 如何打开 CURLOPT_VERBOSE

在 bash 脚本中使用 cURL 的 Javascript 登录

php - curl 重定向,不起作用?

php - Woocommerce 自定义字段不保存

php - 如何从此结果集中求和和计数?

php - Doctrine2 首先查询具有特定值的 orderBy

php - 多张图片上传在 iphone 和 ipad 中不起作用

php - Laravel 5.3 查询数据库并将其传递给所有 View