PHP cURL error 77 when Laravel or Guzzle calls an HTTPS API
cURL error 77: error setting certificate verify locationsShort 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.
Fix it fast
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'));"2Match what you see, then jump to its fix
- 1
The path printed above is not on disk, or is relativecurl.cainfo points at a file that does not existFix - 2
The file exists, but the web server user is not allowed to open itPHP cannot read the file (access rights)Fix - 3
curl.cainfo still prints empty after you set itYou edited a php.ini that PHP does not loadFix
- 1
What does the error look like?
cURL error 77: error setting certificate verify locationsCURLE_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.pem2Fix
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
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.pem2Fix
Make the file readable by everyone and the folder searchable.
sudo chmod 644 /etc/ssl/certs/cacert.pem3Verify
The head command above now prints text, not a permission error.
sudo -u www-data head -c 20 /etc/ssl/certs/cacert.pemConfirmed by curl.se
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 serves2Fix
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-fpm3Verify
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
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
PHP cURL or Guzzle fails with SSL certificate error 60
curl: (60) SSL certificate problem: unable to get local issuer certificate
cURL cannot find a trusted CA file to check the server's certificate against.
3 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack 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 fixBack end
Intervention Image will not save the file in a Laravel app
Can't write image data to path (/var/www/app/public/uploads/photo.jpg)
Intervention Image writes straight to a file path.
3 causes, each with a fixBack end
Laravel file upload returns 413 behind nginx
413 Content Too Large
A 413 means a limit refused the request body before Laravel could use it.
3 causes, each with a fixBack end
Laravel says the bootstrap/cache directory must be present and writable
The /var/www/app/bootstrap/cache directory must be present and writable.
Laravel writes its package manifest into bootstrap/cache and throws when that folder is missing or the current user cannot write to it.
2 causes, each with a fix