PHP curl encounters SSL certificate problem: self signed certificate in certificate chain

Publish: 2018-11-22 | Modify: 2018-11-22

When encountering the error "SSL certificate problem: self signed certificate in certificate chain" while making an HTTPS request using PHP curl, it means that the client's root certificate cannot be verified. Here are two methods to solve this issue.

Method 1:

Ignore certificate verification by adding the following code to the curl method:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

Disadvantage: This method needs to be added to each curl method, which can be a bit cumbersome.

Method 2:

Download the root certificate from the curl official website: cacert.pem, then modify php.ini and add the certificate path, and restart the web server.

# Add the following to php.ini
[SSL]
curl.cainfo = "D:\xampp\php\cacert.pem"
openssl.cafile = "${curl.cainfo}"

This article is partly referenced from: [PHP] PHP cURL https SSL certificate problem: unable to get local issuer certificate


Comments