我正在使用 XAMPP 进行开发。最近我将 xampp 的安装从旧版本升级到 1.7.3。
现在,当我卷曲启用 HTTPS 的网站时,出现以下异常
致命错误:未捕获带有消息的异常“RequestCore_Exception”
'cURL资源:资源
编号#55; cURL 错误:SSL 证书有问题,请验证 CA 证书是否正常。细节:
错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 (60)'
每个人都建议使用PHP代码中的一些特定的curl选项来解决此问题。我认为这不应该是这样。因为我的旧版本 XAMPP 没有任何问题,只是在安装新版本后才发生。
我需要帮助来弄清楚 PHP 安装中的哪些设置发生了变化,Apache 等可以解决这个问题。
I am using XAMPP for development. Recently I upgraded my installation of xampp from an old version to 1.7.3.
Now when I curl HTTPS enabled sites I get the following exception
Fatal error: Uncaught exception 'RequestCore_Exception' with message
'cURL resource: Resource
id #55; cURL error: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (60)'
Everyone suggest using some specific curl options from PHP code to fix this problem. I think this shouldn't be the way. Because I didn't have any problem with my old version of XAMPP and happened only after installing the new version.
I need help to figure out what settings change in my PHP installation, Apache etc can fix this problem.
发布评论
评论(12)
这是 Windows 中非常常见的问题。您只需将
cacert.pem
设置为curl.cainfo
即可。从 PHP 5.3.7 开始,您可以执行以下操作:
php.ini
-- 添加curl.cainfo = "PATH_TO/cacert.pem"否则,您需要对每个 cURL 资源执行以下操作:
It's a pretty common problem in Windows. You need just to set
cacert.pem
tocurl.cainfo
.Since PHP 5.3.7 you could do:
php.ini
-- add curl.cainfo = "PATH_TO/cacert.pem"Otherwise you will need to do the following for every cURL resource:
curl
过去包含接受的证书颁发机构 (CA) 列表,但自 7.18.1 及更高版本起不再捆绑任何 CA 证书。因此,默认情况下,它会拒绝所有 TLS/SSL 证书,因为它们无法验证。您必须获取 CA 的根证书并指向它。更多详细信息,请参阅curl 的有关 TLS/SSL 证书验证的详细信息。
curl
used to include a list of accepted certificate authorities (CAs) but no longer bundles ANY CA certs since 7.18.1 and onwards. So by default it'll reject all TLS/SSL certificates as unverifiable.You'll have to get your CA's root certificate and point curl at it. More details at curl's details on TLS/SSL certificates verification.
警告:这可能会引入 SSL 旨在防止的安全问题,从而使整个代码库变得不安全。它违背了所有推荐的做法。
调用:
之前调用:
但对我来说一个非常简单的修复方法是在 php 文件中
。我认为这会禁用 SSL 证书的所有验证。
Warning: this can introduce security issues that SSL is designed to protect against, rendering your entire codebase insecure. It goes against every recommended practice.
But a really simple fix that worked for me was to call:
before calling:
in the php file.
I believe that this disables all verification of SSL certificates.
来源:http://ademar.name /blog/2006/04/curl-ssl-certificate-problem-v.html
以上所有信息来源:http:// ademar.name/blog/2006/04/curl-ssl-certificate-problem-v.html
Source: http://ademar.name/blog/2006/04/curl-ssl-certificate-problem-v.html
for All above Info Credit Goes to : http://ademar.name/blog/2006/04/curl-ssl-certificate-problem-v.html
上述解决方案很棒,但如果您使用 WampServer,您可能会发现在
php.ini
中设置curl.cainfo
变量不起作用。我最终发现 WampServer 有两个 php.ini 文件:
第一个显然用于通过 Web 浏览器调用 PHP 文件,而第二个用于通过命令行或 <代码>shell_exec()。
TL;DR
如果使用 WampServer,则必须将
curl.cainfo
行添加到两个php.ini
文件中。The above solutions are great, but if you're using WampServer you might find setting the
curl.cainfo
variable inphp.ini
doesn't work.I eventually found WampServer has two
php.ini
files:The first is apparently used for when PHP files are invoked through a web browser, while the second is used when a command is invoked through the command line or
shell_exec()
.TL;DR
If using WampServer, you must add the
curl.cainfo
line to bothphp.ini
files.出于对所有神圣事物的热爱...
就我而言,我必须将
openssl.cafile
PHP 配置变量设置为 PEM 文件路径。我相信确实有很多系统在 PHP 的配置中设置
curl.cainfo
正是所需要的,但在我正在使用的环境中,这是 eboraas/laravel docker 容器,使用 Debian 8 (jessie) 和 PHP 5.6,设置该变量并没有起到作用。我注意到 php -i 的输出没有提及有关该特定配置设置的任何内容,但它确实有几行关于 openssl 的内容。同时存在
openssl.capath
和openssl.cafile
选项,但只需设置第二个选项即可通过 PHP 进行卷曲,最终可以使用 HTTPS URL。For the love of all that is holy...
In my case, I had to set the
openssl.cafile
PHP config variable to the PEM file path.I trust it is very true that there are many systems where setting
curl.cainfo
in PHP's config is exactly what is needed, but in the environment I'm working with, which is the eboraas/laravel docker container, which uses Debian 8 (jessie) and PHP 5.6, setting that variable did not do the trick.I noticed that the output of
php -i
did not mention anything about that particular config setting, but it did have a few lines aboutopenssl
. There is both anopenssl.capath
andopenssl.cafile
option, but just setting the second one allowed curl via PHP to finally be okay with HTTPS URLs.有时,如果您尝试联系的应用程序具有自签名证书,则来自 http:// 的普通 cacert.pem curl.haxx.se/ca/cacert.pem 不能解决问题。
如果您确定服务端点 URL,请通过浏览器点击它,以“X 509 证书与链 (PEM)”格式手动保存证书。将此证书文件指向
Sometimes if the application you try to contact has self signed certificates, the normal cacert.pem from http://curl.haxx.se/ca/cacert.pem does not solve the problem.
If you are sure about the service endpoint url, hit it through browser, save the certificate manually in "X 509 certificate with chain (PEM)" format. Point this certificate file with the
我在 amazon AMI linux 上遇到同样的错误。
我通过在 /etc/php.d/curl.ini 设置 curl.cainfo 来解决
https://gist.github.com/reinaldomendes/97fb2ce8a606ec813c4b
2018 年 10 月添加
在 Amazon Linux v1 上编辑此文件
要添加此行
I have the same error on amazon AMI linux.
I Solved by setting curl.cainfo on /etc/php.d/curl.ini
https://gist.github.com/reinaldomendes/97fb2ce8a606ec813c4b
Addition October 2018
On Amazon Linux v1 edit this file
To add this line
当为 CURLOPT_CAINFO 设置卷曲选项时,请记住使用单引号,使用双引号只会导致另一个错误。所以你的选项应该是这样的:
另外,在你的 php.ini 文件设置中应该写成:(注意我的双引号)
我把它直接放在这样的行下面:
extension=php_curl.dll
(仅出于组织目的,您可以将其放在
php.ini
中的任何位置,我只是将其放在另一个curl 引用附近,这样当我使用关键字curl 进行搜索时,我可以在一个区域中找到两个curl 引用。 )When setting the curl options for CURLOPT_CAINFO please remember to use single quotes, using double quotes will only cause another error. So your option should look like:
Additionally, in your php.ini file setting should be written as:(notice my double quotes)
I put it directly below the line that says this:
extension=php_curl.dll
(For organizing purposes only, you could put it anywhere within your
php.ini
, i just put it close to another curl reference so when I search using keyword curl I caan find both curl references in one area.)当我试图让 GuzzleHttp(Mac 上为 php+apache)从 www.googleapis.com 获取页面时,我最终来到了这里。
这是我的最终解决方案,以防它对任何人有帮助。
查看证书链中是否有任何域向您提供此错误。对我来说,它是 googleapis.com
你会得到这样的结果:
注意:我在解决问题后捕获了这个,你的链输出可能看起来不同。
然后你需要查看证书在 php 中允许。在页面中运行 phpinfo()。
然后查找从页面输出加载的证书文件:
这是您需要通过向其添加正确的证书来修复的文件。
您基本上需要将正确的证书“签名”附加到该文件的末尾。
您可以在这里找到其中一些:如果您需要它们,您可能需要在链中搜索其他内容。
它们看起来像这样:
(注意:这是一个图像,因此人们不会简单地从 stackoverflow 复制/粘贴证书)
一旦正确的证书位于此文件中,请重新启动 apache 并进行测试。
I ended up here when trying to get GuzzleHttp (php+apache on Mac) to get a page from www.googleapis.com.
Here was my final solution in case it helps anyone.
Look at the certificate chain for whatever domain is giving you this error. For me it was googleapis.com
You'll get back something like this:
Note: I captured this after I fixed the issue, to your chain output may look different.
Then you need to look at the certificates allowed in php. Run phpinfo() in a page.
Then look for the certificate file that's loaded from the page output:
This is the file you'll need to fix by adding the correct certificate(s) to it.
You basically need to append the correct certificate "signatures" to the end of this file.
You can find some of them here: You may need to google/search for others in the chain if you need them.
They look like this:
(Note: This is an image so people will not simply copy/paste certificates from stackoverflow)
Once the right certificates are in this file, restart apache and test.
您可以尝试重新安装
ca-certificates
软件包,或者按照此处。You could try to reinstall the
ca-certificates
package, or explicitly allow the certificate in question as described here.解决办法很简单!将此行放在
curl_exec
之前:对我来说它有效。
The solution is very simple! Put this line before
curl_exec
:For me it works.