title: php SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
body: <p>I'm running PHP Version 5.6 as part of XAMPP in MacOSx El Capitan and having error on few <code>https</code> sites. e.g: <code>https://www.google.com/</code></p>
  <p><code>file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed</code></p>
  <p>But no SSL error returned on these sites:</p>
  <ol>
  <li><a href="https://github.com" rel="nofollow noreferrer">GitHub</a></li>
  <li><a href="https://getcomposer.org" rel="nofollow noreferrer">Composer</a></li>
  <li><a href="https://tlstest.paypal.com/" rel="nofollow noreferrer">PayPal TLS Test</a></li>
  </ol>
  <p>Please find the list first what i've tried so far but nothing works.</p>
  <p><strong>Tried Google first:</strong></p>
  <ol>
  <li><a href="https://stackoverflow.com/questions/32211301/ssl-error-ssl3-get-server-certificatecertificate-verify-failed">SSL error SSL3_GET_SERVER_CERTIFICATE:certificate verify failed</a></li>
  <li><a href="https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate">PHP - SSL certificate error: unable to get local issuer certificate</a></li>
  <li><a href="https://stackoverflow.com/questions/6400300/https-and-ssl3-get-server-certificatecertificate-verify-failed-ca-is-ok">HTTPS and SSL3_GET_SERVER_CERTIFICATE:certificate verify failed, CA is OK</a></li>
  </ol>
  <h1>Manual</h1>
  <p><strong>1. Updated cert.pem file</strong></p>
  <p><code>php -r 'print_r(openssl_get_cert_locations());'</code></p>
  <p>and result was.</p>
  <pre><code>Array
  (
      [default_cert_file] =&gt; /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
      [default_cert_file_env] =&gt; SSL_CERT_FILE
      [default_cert_dir] =&gt; /Applications/XAMPP/xamppfiles/share/openssl/certs
      [default_cert_dir_env] =&gt; SSL_CERT_DIR
      [default_private_dir] =&gt; /Applications/XAMPP/xamppfiles/share/openssl/private
      [default_default_cert_area] =&gt; /Applications/XAMPP/xamppfiles/share/openssl
      [ini_cafile] =&gt; /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
      [ini_capath] =&gt;
  )
  </code></pre>
  <p>Saved <a href="https://curl.haxx.se/ca/cacert.pem" rel="nofollow noreferrer">this file cacert.pem</a> in <code>/Applications/XAMPP/xamppfiles/share/openssl/cert.pem</code></p>
  <p>Updated <code>php.ini</code> with following</p>
  <pre><code>openssl.cafile = /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
  curl.cainfo    = /Applications/XAMPP/xamppfiles/share/openssl/cert.pem
  </code></pre>
  <p>Restarted Apache but no succes. Tried to read pem file (no error returned)</p>
  <pre><code>echo file_get_contents(&quot;/Applications/XAMPP/xamppfiles/share/openssl/cert.pem&quot;);
  </code></pre>
  <p><strong>Test Case</strong></p>
  <p>It works fine on <code>github.com</code> <code>getcomposer.org</code> <code>paypal.com</code> but not on <code>google.com</code> (google.com works as well on my windows system)</p>
  <pre><code>php -r '$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, &quot;https://tlstest.paypal.com/&quot;); var_dump(curl_exec($ch)); var_dump(curl_error($ch));'
  </code></pre>
  <p>Result: <code>PayPal_Connection_OKbool(true)</code></p>
  <p>But on <code>google.com</code></p>
  <pre><code>php -r '$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, &quot;https://www.google.com/&quot;); var_dump(curl_exec($ch)); var_dump(curl_error($ch));'
  </code></pre>
  <p>Result: <code>string(63) &quot;SSL certificate problem: unable to get local issuer certificate&quot;</code></p>
  <p><strong>P.S:</strong> Disabling peer verification won't be acceptable.</p>