cURL error 60: SSL certificate in Laravel 5.4

后端 未结 8 843
有刺的猬
有刺的猬 2020-12-02 20:47

Full Error

RequestException in CurlFactory.php line 187: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see ht

相关标签:
8条回答
  • 2020-12-02 21:49
    • Solution suggested by some users to make changes to \vendor\guzzlehttp\guzzle\src\Client.php file is the worst advice, as manual changes made to vendor folder are overwritten if you run composer update command.
    • Solution suggested by Jeffrey is a dirty, shorthand fix but not recommended in production applications.
    • Solution suggested by kjdion84 is perfect if you have access to php.ini file on web server. In case you are using Shared Hosting, it may not be possible to edit php.ini file.

    When you don't have access to php.ini file (e.g. Shared Hosting)

    1. Download this file: http://curl.haxx.se/ca/cacert.pem
    2. Place this file in the root folder of your Laravel project.
    3. Add verify key to GuzzleHttp\Client constructor with its value as path to cacert.pem file.

    With Laravel 5.7 and GuzzleHttp 6.0

    // https://example.com/v1/current.json?key1=value1&key2=value2
    
    $guzzleClient = new GuzzleHttp\Client([
        'base_uri' => 'https://example.com',
        'verify' => base_path('cacert.pem'),
    ]);
    
    $response = $guzzleClient->get('v1/current.json', [
        'query' => [
            'key1' => 'value1',
            'key2' => 'value2',
        ]
    ]);
    
    $response = json_decode($response->getBody()->getContents(), true);
    
    0 讨论(0)
  • 2020-12-02 21:52

    A quick solution but insecure (not recommended).

    Using cURL:

    Set CURLOPT_SSL_VERIYPEER to false
    

    Using Guzzle: Set verify to false, for example

    $client->request('GET', 'https://somewebsite.com', ['verify' => false]);
    
    0 讨论(0)
提交回复
热议问题