Curl not connecting on windows (SSL problem)

I have just installed Acquia Dev Desktop on a windows laptop and set up a Drupal site. The Drupal site retreives information from a REST webservice. It is using php's curl to do the requests and retreive the responses. Unfortunately the curl requests fail.
 

Curl call doesn't get a response

The curl request is send to an external https resource. But no information is retreived.

So we add some curl debugging statements to see what is wrong.

$url = 'https://www.kpn.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);

// Show result.
echo '*Result*';
var_dump($result);

// Show status code.
echo '*status code* '. curl_getinfo($ch, CURLINFO_HTTP_CODE);

// Show errors.
if(curl_errno($ch)){
  echo '*Curl error* ' . curl_error($ch);
}

// Show info.
$info = curl_getinfo($ch);
echo '*Info*';
var_dump($info);
	
// We are done, close the connection.
curl_close ($ch);  

The status code is zero and the curl error is:

"error setting certificate verify locations: CAfile: C:\Program Files (x86)\DevDesktop\common\cert\cacert.

The problem seems to be to do with certificates. Curl can not verify the SSL certificate of the resources it is trying to contact. There are two ways of solving this.

Install certificates

  1. Download the cacert.perm file from http://curl.haxx.se/docs/caextract.html.
  2. Curl must be able to find this file. Place the file in the directory specified in the error.
  3. Run curl again.

The directory where the file needs to be place can be configured by editing the value of the "curl.cainfo" option in the php.ini file.

More information:

Do not perform ssl certificate verification

Add this line to your code:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

More information:

 

Final thought

Why was this not a problem when I was using XAMPP ? Because XAMPP is shipped and configured with a certificate file. The curl-ca-bundle.crt file is located in the apache/bin directory and configured in the php.ini file.