最近在帮客户排查一个问题时,遇到一个500错误,打开PHP Debug模式,发现详细报错内容如下:AWS HTTP error: cURL error 60: SSL certificate problem: certificate has expired
,一看这个提示以为是目标地址SSL证书过期了,但反复确认目标SSL证书正常,并且其它设备均可请求,但是宝塔的PHP环境无法请求目标URL,尝试更换PHP版本依然如此。
解决办法1:
进入服务器终端,执行下面的命令下载根证书:
#下载根证书
wget --no-check-certificate https://curl.haxx.se/ca/cacert.pem
在宝塔后台找到你对应的PHP版本 - 设置 - 配置文件.
搜索下面2个关键词:curl.cainfo/openssl.cafile
将这2参数的路径修改为上面cacert.pem
证书的路径,比如:
curl.cainfo = /xxx/cacert.pem
openssl.cafile=/xxx/cacert.pem
然后重启下PHP,再次测试,问题解决。
解决办法2:
curl 取消 ssl 检查
可以在 curl 相关代码中添加下面的代码
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
例子:
function curl_post1($url, $data = array(), $header = array(), $timeout = 80, $port = 80)
{
$ch = curl_init ( $url );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_FRESH_CONNECT, 1 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_FORBID_REUSE, 1 );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 30 );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen ( $data ) ) );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //todo::增加该行
$result = array();
$result['result'] = curl_exec ( $ch );
echo $functionName . " : Request Info : url: " . $url . " ,send data: " . $data . " \n";
echo $functionName . " : Respnse Info : " . $ret . " \n";
curl_close ( $ch );
return $result;
}
解决宝塔面板报错“SSL certificate problem: certificate has expired” | 青山绿水