Maaz Zindani

Loading the index…

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

PHP cURL or Guzzle fails with SSL certificate error 60

ErrorcURL error 60: SSL certificate problem: unable to get local issuer certificate

Short answer

cURL cannot find a trusted CA file to check the server's certificate against. Download a current CA bundle, set curl.cainfo to its absolute path in the php.ini that your PHP really loads, then restart PHP. Do not set verify to false; that removes the protection.

  • Applies to PHP 8.3, PHP 8.4, curl 8.x, Guzzle 7
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which php.ini PHP loaded and whether curl.cainfo is already set. Edit that file, not another copy.

    php --ini
    php -r "var_dump(ini_get('curl.cainfo'), ini_get('openssl.cafile'));"
  2. 2Match what you see, then jump to its fix

    1. 1curl.cainfo is empty and the error appears for every https site.No CA bundle is configured for PHPFix
    2. 2curl.cainfo is set in a file but ini_get still returns an empty value.You edited a php.ini that PHP does not loadFix
    3. 3Only one API or a corporate proxy host fails; others work.One request needs its own CA fileFix

What does the error look like?

  • cURL error 60: SSL certificate problem: unable to get local issuer certificate
  • curl: (60) SSL certificate problem: unable to get local issuer certificate

Cause 1 of 3

No CA bundle is configured for PHP

1Check

curl verifies certificates by default and needs a store of trusted CAs. PHP's curl.cainfo ini setting provides the default file and must be an absolute path. On many Windows installs nothing is set.

php -r "var_dump(ini_get('curl.cainfo'));"
curl -s -o /dev/null -w "%{http_code}\n" https://example.com

2Fix

Download the PEM bundle that curl publishes, store it outside the web root, and set the path in php.ini.

; php.ini
curl.cainfo = "/etc/ssl/certs/cacert.pem"
; Windows example:
; curl.cainfo = "C:\php\extras\ssl\cacert.pem"

3Verify

Restart PHP-FPM or the web server, and the value shows up.

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

Confirmed by php.net

Did this fix it?

Cause 2 of 3

You edited a php.ini that PHP does not load

1Check

CLI and web server PHP can read different files. The loaded file is listed by php --ini, and by phpinfo() for the web server.

php --ini
php -r "var_dump(php_ini_loaded_file());"

2Fix

Put the setting in the file each SAPI loads, or in a .ini file inside the directory that php --ini lists as the scan directory for additional .ini files.

# in each php.ini that is loaded (CLI and web server):
curl.cainfo = "/etc/ssl/certs/cacert.pem"

3Verify

Compare both SAPIs after saving the file and restarting.

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

Confirmed by php.net

Did this fix it?

Cause 3 of 3

One request needs its own CA file

1Check

A private CA or an intercepting proxy is not in the public bundle, so that one host fails verification. curl can verify against a single file you give it for that transfer.

curl --cacert /path/to/corp-ca.pem -I https://api.internal.example

2Fix

Pass the file for that client only, for example in Guzzle.

$client = new GuzzleHttp\Client(['verify' => '/path/to/corp-ca.pem']);

3Verify

The request now succeeds and other hosts are unaffected.

php -r "echo (new GuzzleHttp\Client(['verify'=>'/path/to/corp-ca.pem']))->get('https://api.internal.example')->getStatusCode();"

Confirmed by curl.se

Did this fix it?

How do I stop it coming back?

  • Refresh the CA bundle on a schedule; an old bundle misses newer roots.
  • Never ship verify=false or CURLOPT_SSL_VERIFYPEER=0; curl's docs call disabling verification strongly discouraged.
  • Keep one shared ini file for CLI and FPM so they cannot drift.

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

Apache returns 403 when a URL contains %3F

a request like /page%3Fname=test is refused while /page?name=test works

Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.

2 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.