本地 WordPress 和 MAMP wp_remote_get():cURL 错误 60:SSL 证书问题:无法获取本地颁发者证书

Rya*_*orn 3 php wordpress ssl curl mamp

我有一个在 MAMP Pro (macos) 上本地运行的网站,并且在使用时不断收到 cURL 错误wp_remote_get()

我搜索并尝试了多种解决方案,但似乎没有任何效果。

我的代码:

$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"
Run Code Online (Sandbox Code Playgroud)

我有:

  1. 从https://curl.haxx.se/docs/caextract.html下载最新的 CA 文件
  2. 替换了我的 MAMP OpenSSL 安装中的 cacert.pem 文件:/Applications/MAMP/Library/OpenSSL/certs/cacert.pem
  3. 打开两个相关的 php.ini 文件。一个位于 /Applications/MAMP/conf/php7.4.2/php.ini ,另一个位于 /Applications/MAMP/bin/php/php7.4.2/conf/php.ini
  4. 将 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”
  5. 我还尝试通过 MAMP GUI 指定curl.cainfo、openssl.cafile、openssl.capath:文件>编辑模板> PHP(php.ini) > 7.4.2

Hel*_*ire 5

这更多的是本地解决方法。您可以在本地站点内禁用 SSL 验证。这可以通过将此行添加到文件中wp-includes/functions.php/wp-content/themes/YOUR_THEME/functions.php

add_filter('https_ssl_verify', '__return_false');
Run Code Online (Sandbox Code Playgroud)