Search code examples
php.netsslcurl

cURL error 60: SSL certificate problem: self-signed certificate


I did copy the latest cacert.pem to the folder curl.cainfo="C:\xampp\php\extras\ssl\cacert.pem" but still have the error 'curl: (60) SSL certificate problem' in my localhost.


Solution

  • In your php.ini also update this param with same path to pem file openssl.cafile="C:\xampp\php\extras\ssl\cacert.pem", than restart wamp.

    You can also put pem path inside php code:

    // For CURL
    curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__)."/path-to-file/cacert.pem");    
    
    // For Guzzle
    use GuzzleHttp\Client;
    $this->client = new Client([
        'verify' => '/path/to/where/you/saved/your.pem',
    ]);
    

    This workaround is dangerous and not recommended for production, but it is ok to use for localhost environment:

    // For CURL
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    
    // For Guzzle
    use GuzzleHttp\Client;
    $this->client = new Client([
        'verify' => false,
    ]);