Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP cURL error 77 when Laravel or Guzzle calls an HTTPS API

ErrorcURL error 77: error setting certificate verify locations

Short answer

Error 77 means libcurl could not read the CA certificate file it was told to use. In PHP that file comes from the curl.cainfo setting in php.ini. Download a current cacert.pem, set curl.cainfo to its absolute path, make sure PHP can read it, and restart PHP so the loaded php.ini applies.

  • Applies to PHP 8.3, Laravel 11, Guzzle 7, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP which php.ini it really loaded and what curl.cainfo is set to. Do this with the same PHP binary your web server or queue worker uses.

    php --ini | grep "Loaded Configuration File"
    php -r "var_dump(ini_get('curl.cainfo'));"
  2. 2Match what you see, then jump to its fix

    1. 1The path printed above is not on disk, or is relativecurl.cainfo points at a file that does not existFix
    2. 2The file exists, but the web server user is not allowed to open itPHP cannot read the file (access rights)Fix
    3. 3curl.cainfo still prints empty after you set itYou edited a php.ini that PHP does not loadFix

What does the error look like?

  • cURL error 77: error setting certificate verify locations
  • CURLE_SSL_CACERT_BADFILE

Cause 1 of 3

curl.cainfo points at a file that does not exist

1Check

curl.cainfo must be an absolute path. A copied php.ini, a moved folder or a leftover Windows path leaves a path that points nowhere.

php -r "echo ini_get('curl.cainfo');"
ls -l /etc/ssl/certs/cacert.pem

2Fix

Download the CA bundle, store it in a stable folder and put its absolute path in php.ini.

sudo curl -o /etc/ssl/certs/cacert.pem https://curl.se/ca/cacert.pem

; php.ini
curl.cainfo = "/etc/ssl/certs/cacert.pem"

3Verify

Restart PHP and read the value back.

sudo systemctl restart php8.3-fpm
php -r "echo ini_get('curl.cainfo');"

Confirmed by php.net

Did this fix it?

Cause 2 of 3

PHP cannot read the file (access rights)

1Check

libcurl reports this error for a problem with the path or with access rights. The CLI may work as your user while PHP-FPM runs as another.

sudo -u www-data head -c 20 /etc/ssl/certs/cacert.pem

2Fix

Make the file readable by everyone and the folder searchable.

sudo chmod 644 /etc/ssl/certs/cacert.pem

3Verify

The head command above now prints text, not a permission error.

sudo -u www-data head -c 20 /etc/ssl/certs/cacert.pem

Confirmed by curl.se

Did this fix it?

Cause 3 of 3

You edited a php.ini that PHP does not load

1Check

The command line and PHP-FPM or Apache can load different php.ini files. The Loaded Configuration File line in phpinfo() names the one that applies.

php --ini
# and phpinfo() output from a page the web server serves

2Fix

Edit the file named for the SAPI that runs your app, then restart that service. curl.cainfo cannot be set with ini_set() at run time.

sudo systemctl restart php8.3-fpm

3Verify

Read the value back from the web SAPI and call the API again from the app.

php -r "echo ini_get('curl.cainfo');"

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Refresh cacert.pem now and then; the curl project republishes it as CAs change.
  • Keep the bundle outside the project folder so deployments do not delete it.
  • Do not turn off certificate verification to make the error go away.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Why a Filament panel feels slow on a Laravel server

The panel is fast on a small demo and slow once there are many resources, pages and widgets

A slow Filament panel on a server is most often running without the production caches.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.