title: How to fix PHP error: Unable to get local issuer certificate?
body: <p>This is my environment setup:</p>
  
  <pre><code>Mac OS Sierra (10.12.2)
  XAMPP 5.6.23
  PHP 5.6.23
  </code></pre>
  
  <p>I'm using the PHP version that is included with XAMPP:</p>
  
  <pre><code>$ which php
  /Applications/XAMPP/bin/php
  $ php -v
  PHP 5.6.23 (cli) (built: Jun 24 2016 09:25:00)
  Copyright (c) 1997-2016 The PHP Group
  Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
  </code></pre>
  
  <p>This is my PHP code:</p>
  
  <pre><code>  $postData = array('FORM_DATA' =&gt; 'data');
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL =&gt; 'https://testhub.banregio.com/adq',
        CURLOPT_RETURNTRANSFER =&gt; true,
        CURLOPT_POST =&gt; true,
        CURLOPT_POSTFIELDS =&gt; $postData,
        CURLOPT_FOLLOWLOCATION =&gt; true
    ));
  
    $response = curl_exec($curl);
    $err = curl_error($curl);
    echo $response;
    echo $err;
    curl_close($curl);
  </code></pre>
  
  <p>I already added the following line to the <code>php.ini</code> file and, of course, downloaded the <code>cacert.pem</code> file from <a href="https://curl.haxx.se/ca/cacert.pem" rel="nofollow noreferrer">https://curl.haxx.se/ca/cacert.pem</a>:</p>
  
  <pre><code>curl.cainfo=/Applications/XAMPP/xamppfiles/etc/cacert.pem
  </code></pre>
  
  <p>My php.ini file is located in:</p>
  
  <pre><code>$ php --ini
  Configuration File (php.ini) Path: /Applications/XAMPP/xamppfiles/etc
  Loaded Configuration File:         /Applications/XAMPP/xamppfiles/etc/php.ini
  Scan for additional .ini files in: (none)
  Additional .ini files parsed:      (none)
  </code></pre>
  
  <p><strong>Didn't work.</strong> I can't set <code>CURLOPT_SSL_VERIFYPEER</code> to <code>false</code>.</p>
  
  <p>Next, I added these options for <code>cURL</code> in the code above: </p>
  
  <pre><code>CURLOPT_SSL_VERIFYPEER =&gt; true,
  CURLOPT_SSL_VERIFYHOST =&gt; 2,
  CURLOPT_CAINFO =&gt; '/path/to/my/exported/certificate.crt'
  </code></pre>
  
  <p>The website has the following certificate:</p>
  
  <p><a href="https://i.stack.imgur.com/NgZt0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NgZt0.png" alt="enter image description here"></a></p>
  
  <p>Of course, I had to export it from <strong>Keychain Access</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/D3nBR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D3nBR.png" alt="enter image description here"></a></p>
  
  <p><strong>Keychain Access</strong> can export <code>*.pem</code> and <code>*.cer</code> certificates. I tried with both. Actually, I renamed the <code>*.cer</code> certificate to <code>*.crt</code>.</p>
  
  <p><strong>Didn't work either.</strong></p>