Resolving error "SSL certificate problem: self signed certificate in certificate chain"

Summary

Developers using cURL in PHP may encounter an "SSL certificate problem: self signed certificate in certificate chain" error when connecting to servers with untrusted self-signed certificates. To resolve this, download the standard CA certificates from curl.haxx.se and the specific CA certificate for the problematic server. Append the server's certificate content to the downloaded `cacert.pem` file. Finally, update the `curl.cainfo` directive in `php.ini` to point to the absolute path of this combined certificate file, then restart the server to apply the changes. This process ensures cURL trusts the necessary certificates for secure connections.

In a PHP application, cURL is frequently used to make connection to remote server to request some resource. It can be used to transfer data with different protocols such as HTTP, HTTPS, FTP etc.

While using cURL in PHP, someone may get an error with message similar to "SSL certificate problem: self signed certificate in certificate chain".

This may happen when cURL tries to make a SSL connection server and the server returns a server certificate which is self-signed and it's not trusted by the client(in the client CA store). In this case, you may need to follow below steps to resolve this issue.

  1. Download the CA certs from http://curl.haxx.se/ca/cacert.pem.
  2. Download the CA certificate of the server which sends the certificate chain containing the self-signed certificate. For example, if you are building a Twilio application, you can download the certificate file from https://www.thawte.com/roots/thawte_Premium_Server_CA.pem
  3. Open the certificate file downloaded in step 2 and copy the contents(Usually BASE64 encoded certificate) to the one downloaded in step 1. And save the certificate file.
  4. Open php.ini, go to the section [curl] and update it like
    [curl]
    ; A default value for the CURLOPT_CAINFO option. This is required to be an
    ; absolute path.
    curl.cainfo = c:/wamp/cacert/cacert.pem
  5. Save it and restart your server.

One last remind, the curl.cainfo should point to an absolute path.

PHP SSL CURL TWILIO

  RELATED

  COMMENT

1
Anonymous
Jun 23, 2017 at 7:33 am

This article is total crap