cURL error 60: SSL certificate: unable to get local issuer certificate

前端 未结 19 1277
天涯浪人
天涯浪人 2020-11-22 10:51

I use WAMP on a local development environment and am trying to charge a credit card but get the error message:

cURL error 60: SSL certificate problem:

相关标签:
19条回答
  • 2020-11-22 11:31

    If you are using PHP 5.6 with Guzzle, Guzzle has switched to using the PHP libraries autodetect for certificates rather than it's process (ref). PHP outlines the changes here.

    Finding out Where PHP/Guzzle is Looking for Certificates

    You can dump where PHP is looking using the following PHP command:

     var_dump(openssl_get_cert_locations());
    

    Getting a Certificate Bundle

    For OS X testing, you can use homebrew to install openssl brew install openssl and then use openssl.cafile=/usr/local/etc/openssl/cert.pem in your php.ini or Zend Server settings (under OpenSSL).

    A certificate bundle is also available from curl/Mozilla on the curl website: https://curl.haxx.se/docs/caextract.html

    Telling PHP Where the Certificates Are

    Once you have a bundle, either place it where PHP is already looking (which you found out above) or update openssl.cafile in php.ini. (Generally, /etc/php.ini or /etc/php/7.0/cli/php.ini or /etc/php/php.ini on Unix.)

    0 讨论(0)
  • 2020-11-22 11:32

    Working solution assuming your on Windows using XAMPP:

    XAMPP server

    1. Similar for other environment
      • download and extract for cacert.pem here (a clean file format/data)

    https://curl.haxx.se/docs/caextract.html

    1. Put it here in the following directory.

    C:\xampp\php\extras\ssl\cacert.pem

    1. In your php.ini put this line in this section ("c:\xampp\php\php.ini"):
    ;;;;;;;;;;;;;;;;;;;;
    ; php.ini Options  ;
    ;;;;;;;;;;;;;;;;;;;;
    
    curl.cainfo = "C:\xampp\php\extras\ssl\cacert.pem"
    
    1. Restart your webserver/apache

    2. Problem solved!

    (Reference: https://laracasts.com/discuss/channels/general-discussion/curl-error-60-ssl-certificate-problem-unable-to-get-local-issuer-certificate)

    0 讨论(0)
  • 2020-11-22 11:33

    I have a proper solution of this problem, lets try and understand the root cause of this issue. This issue comes when remote servers ssl cannot be verified using root certificates in your system's certificate store or remote ssl is not installed along with chain certificates. If you have a linux system with root ssh access, then in this case you can try updating your certificate store with below command:

    update-ca-certificates

    If still, it doesn't work then you need to add root and interim certificate of remote server in your cert store. You can download root and intermediate certs and add them in /usr/local/share/ca-certificates directory and then run command update-ca-certificates. This should do the trick. Similarly for windows you can search how to add root and intermediate cert.

    The other way you can solve this problem is by asking remote server team to add ssl certificate as a bundle of domain root cert, intermediate cert and root cert.

    0 讨论(0)
  • 2020-11-22 11:34

    I spent too much time to figure out this problem for me.

    I had PHP version 5.5 and I needed to upgrade to 5.6.

    In versions < 5.6 Guzzle will use it's own cacert.pem file, but in higher versions of PHP it will use system's cacert.pem file.

    I also downloaded file from here https://curl.haxx.se/docs/caextract.html and set it in php.ini.

    Answer found in Guzzles StreamHandler.php file https://github.com/guzzle/guzzle/blob/0773d442aa96baf19d7195f14ba6e9c2da11f8ed/src/Handler/StreamHandler.php#L437

            // PHP 5.6 or greater will find the system cert by default. When
            // < 5.6, use the Guzzle bundled cacert.
    
    0 讨论(0)
  • 2020-11-22 11:41

    What i did was use var_dump(openssl_get_cert_locations()); die; in any php script, which gave me the information about defaults that my local php was using:

    array (size=8)
      'default_cert_file' => string 'c:/openssl-1.0.1c/ssl/cert.pem' (length=30)
      'default_cert_file_env' => string 'SSL_CERT_FILE' (length=13)
      'default_cert_dir' => string 'c:/openssl-1.0.1c/ssl/certs' (length=27)
      'default_cert_dir_env' => string 'SSL_CERT_DIR' (length=12)
      'default_private_dir' => string 'c:/openssl-1.0.1c/ssl/private' (length=29)
      'default_default_cert_area' => string 'c:/openssl-1.0.1c/ssl' (length=21)
      'ini_cafile' => string 'E:\xampp\php\extras\ssl\cacert.pem' (length=34)
      'ini_capath' => string '' (length=0)
    

    As you can notice, i have set the ini_cafile or the ini option curl.cainfo. But in my case, curl would try to use the "default_cert_file" which did not exist.

    I copied the file from https://curl.haxx.se/ca/cacert.pem into the location for "default_cert_file" (c:/openssl-1.0.1c/ssl/cert.pem) and i was able to get it to work.

    This was the only solution for me.

    0 讨论(0)
  • 2020-11-22 11:42

    I found a solution that worked for me. I downgraded from the latest guzzle to version ~4.0 and it worked.

    In composer.json add "guzzlehttp/guzzle": "~4.0"

    Hope it helps someone

    0 讨论(0)
提交回复
热议问题