【问题标题】:How to configure openssl to work with file_get_contents如何配置 openssl 以使用 file_get_contents
【发布时间】:2021-03-02 16:35:45
【问题描述】:

我们运行 apache2 服务器并希望使用 google recaptcha,因为我们的时事通讯中有大量机器人。

因此,我实现了一些开发人员 php 代码行,它们通常应该可以工作......但不是在我的服务器上。 我进一步调查,发现函数 file_get_contents() 以 SSL 错误结束。

file_get_contents(self::SITE_VERIFY_URL, false, $context)

您可以在下面找到服务器日志文件的摘录。

PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in /var/www/html/app/lib/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php on line 68
PHP Warning:  file_get_contents(): Failed to enable crypto in /var/www/html/app/lib/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php on line 68
PHP Warning:  file_get_contents(https://www.google.com/recaptcha/api/siteverify): failed to open stream: operation failed in /var/www/html/app/lib/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php on line 68

这让我得出结论,Openssl 配置错误。 所以我:

  • 使用 apt-get purge ca-certificate 重新安装 ca-certificate
  • 还下载了 cacert.pem 并将其链接到 php.ini 中
  • 检查 curl 是否正常工作,但不能正常工作(每次调用 curl 都以 curl: (60) SSL certificate problem: unable to get local issuer certificate 结尾
  • 检查了 openssl.cnf,我觉得没问题。

任何解决这个问题的想法都会很棒。

【问题讨论】:

  • 你能在你的服务器上创建一个包含<?php phpinfo(); ?> 的文件,然后显示它对openssl.cafileopenssl.capath 的值吗? PHP 仍然可能未正确配置以在正确的位置查看证书。 This answer 显示了各种 Linux 发行版的正确路径。您需要确保 openssl.cafilecurl.cainfo 都设置为适当的 .pem 文件。
  • openssl.cafile 的值为/etc/ssl/certs/ca-certificates.crtopenssl.capath 的值为/etc/ssl/certs。我检查了crt文件。它在文件夹中,格式看起来不错,最近更新了。当我回到从谷歌检索对象的初始问题时,错误消息发生了变化:failed loading cafile stream: /etc/ssl/certs/ca-certificates.crt' in /var/www/html/app/lib/vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php on line 68

标签: php ssl curl openssl recaptcha


【解决方案1】:

所以我发现了问题: 首先,我根据draw010的评论更改了文件路径。 然后我根据这篇文章修复了我的服务器上的问题,文件权限为 /etc/ssl/certs:https://askubuntu.com/a/636979

现在 file_get_contents 不会调用任何错误,recaptcha 可以顺利运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 2017-01-09
    • 2012-12-14
    • 2013-12-10
    • 1970-01-01
    • 2013-10-23
    相关资源
    最近更新 更多