How To Fix cURL Error 60 SSL Certificate Problem in Laravel?

I’m working on a Laravel project that uses Guzzle to make API requests to a third-party service. Everything was working fine until today when I started getting this error:

URL error 60: SSL certificate problem: certificate has expired

I tried renewing the Let’s Encrypt SSL certificate, clearing the cache, and restarting the server, but nothing changed.

What am I missing? How can I solve this problem? Any help would be appreciated.

The cURL error 60: SSL certificate problem occurs when cURL tries to verify the server’s SSL certificate you are trying to connect to. Depending on your environment and preferences, there are a few ways to fix this problem.

One way is to disable the SSL verification by setting the ‘verify’ option to false in your Guzzle client configuration.
This can be done either globally in your vendor/guzzlehttp/guzzle/src/Client.php file.

$defaults = [
    'allow_redirects' => RedirectMiddleware::$defaultSettings,
    'http_errors'     => true,
    'decode_content'  => true,
    'verify'          => false, // Disable the SSL verification
    'cookies'         => false,
    'idn_conversion'  => true,
];

Or locally for each request. For example:

$res = Http::withOptions(['verify' => false])->get ('https://example.com/someapi');

However, this is not recommended for production applications, as it exposes you to potential security risks. Also, if you modify the vendor folder manually, your changes will be lost when you execute the composer update command. You should update those modifications accordingly.

Another way is to download a bundle of the CA certificate file and add it to your php.ini file.

  1. Download the free certificate file from http://curl.haxx.se/ca/cacert.pem
  2. Save it as a “cacert.pem” somewhere on your server.
  3. Open php.ini and find this line
;curl.cainfo
  1. Add the path of the certificate to “curl.cainfo” and remove the semicolon ( ; ) as follows.
curl.cainfo = "[path-to-the-file]\cacert.pem"
  1. Save and close your php.ini file and restart your server for the changes to take effect.

This will tell cURL where to look for the certificates to verify the SSL connection.