如何解决本地WordPress和MAMP wp_remote_get:cURL错误60:SSL证书问题:无法获取本地发行者证书
我有一个在MAMP Pro(macos)上本地运行的网站,当我使用wp_remote_get()
时不断出现cURL错误
我已经搜索并尝试了多种解决方案,但似乎没有任何效果。
我的代码:
$url = site_url() . '/wp-json/wp/v2/my-cpt'; // This works just fine and shows up in the browser correctly
$response = wp_remote_get( $url ); // this outputs the cURL error: "cURL error 60: SSL certificate problem: unable to get local issuer certificate"
我有:
- 从https://curl.haxx.se/docs/caextract.html下载了最新的CA文件
- 在我的MAMP OpenSSL安装中替换了cacert.pem文件:/Applications/MAMP/Library/OpenSSL/certs/cacert.pem
- 打开了两个相关的php.ini文件。一个位于/Applications/MAMP/conf/php7.4.2/php.ini,另一个位于/Applications/MAMP/bin/php/php7.4.2/conf/php.ini
- 将URL添加到新的cacert.pem curl.cainfo =“ /Applications/MAMP/Library/OpenSSL/certs/cacert.pem” openssl.cafile =“ / Applications / MAMP / Library / OpenSSL / certs / cacert。 pem“ openssl.capath =” / Applications / MAMP / Library / OpenSSL / certs“
- 我还尝试指定curl.cainfo,openssl.cafile,openssl.capath 通过MAMP GUI:文件>编辑模板> PHP(php.ini)> 7.4.2
解决方法
这更像是一种本地解决方法。您可以在本地站点中禁用 SSL 验证。这可以通过将此行添加到文件 wp-includes/functions.php
或
/wp-content/themes/YOUR_THEME/functions.php
add_filter('https_ssl_verify','__return_false');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。