【发布时间】: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.cafile和openssl.capath的值吗? PHP 仍然可能未正确配置以在正确的位置查看证书。 This answer 显示了各种 Linux 发行版的正确路径。您需要确保openssl.cafile和curl.cainfo都设置为适当的 .pem 文件。 -
openssl.cafile的值为/etc/ssl/certs/ca-certificates.crt,openssl.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