修复cURL error 60: SSL certificate problem: certificate has expired错误

发布时间:2021/12/21 13:15:36 打印 字号:

WordPress使用Let’s Encrypt方式api安装了错误:

$res = wp_remote_get( 'https://gworgcom/' );

if( is_wp_error( $res ) ){

echo $res->get_error_message();}

然后提示:cURL error 60: SSL certificate problem: certificate has expired

这错误是因为SSL证书根证书到期,发生的错误,需要补充根证书。


使用Gworg证书解决办法

域名提交到Gworg替换证书就可以了,有效期1年,浏览器信任度99%,带安全签章。


继续使用Let’s Encrypt证书解决办法。

Let’s Encrypt有效期3个月,会导致大部分浏览器不信任,网站不能访问。以下是解决办法说明

您需要更新/wp-includes/certificates/ca-bundle.crt文件的内容,将其更改为https://curl.se/ca/cacert.pem文件的内容。

在这种情况下更改核心文件是可以接受的,因为下次更新WP时,问题就会消失。

手动替换内容更新以解决问题

下载此文件 https://curl.se/ca/cacert.pem。

使用上述下载以更新/wp-includes/certificates/ca-bundle.crt的内容。

好了,报错将不再出现。

或添加代码片段来修复报错

当您能够从管理面板运行代码时,使用代码会很方便,例如使用Code Snippets插件。

将以下代码添加到 themes functions.php 文件中(或在Code Snippets 插件中)

/**
 * Goto http://yoursite.com/?update-wp-ca-bundle
 */if( isset( $_GET['update-wp-ca-bundle'] ) ){

	$crt_file = ABSPATH . WPINC . '/certificates/ca-bundle.crt';
	$new_crt_url = 'http://curl.haxx.se/ca/cacert.pem';

	if( is_writable( $crt_file ) ){
		$new_str = file_get_contents( $new_crt_url );

		if( $new_str && strpos( $new_str, 'Bundle of CA Root Certificates' ) ){
			$up = file_put_contents( $crt_file, $new_str );

			echo $up ? 'OK: ca-bundle.crt updated' : 'ERROR: can`t put data to ca-bundle.crt';
		}
		else {
			echo 'ERROR: can\'t download curl.haxx.se/ca/cacert.pem';
		}
	}
	else {
		echo 'ERROR: ca-bundle.crt not writable';
	}

	exit;

使用后删除代码。

访问http://yoursite.com/?update-wp-ca-bundle页面。(yoursite.com替换自己域名)