Guzzle refuses an HTTPS request because the certificate cannot be verified
SSL certificate problem: unable to get local issuer certificateShort answer
Guzzle verifies certificates by default, using the operating system's CA bundle. When PHP cannot find a bundle, or the server uses a private CA, the request fails. Point verify at a CA file, or set openssl.cafile in php.ini. verify => false switches the check off and is unsafe outside a throwaway test.
Fix it fast
1Find out which cause you have
Find out which of the two situations you are in: a public site whose chain your machine cannot check, or a private or self-signed server. A browser or curl against the same URL tells you.
curl -vI https://example.com 2>&1 | grep -i -E "SSL|certificate|verify" php -r "echo ini_get('openssl.cafile'), PHP_EOL;"2Match what you see, then jump to its fix
- 1
Public sites fail the same way from PHP, and the openssl.cafile setting prints nothing.PHP has no CA bundle to verify againstFix - 2
Only your internal host fails, and browsers on managed machines trust it while PHP does not.The server uses a private or self-signed certificate authorityFix - 3
A development box with a throwaway certificate and no real data.You only need it off for a local testFix
- 1
What does the error look like?
SSL certificate problem: unable to get local issuer certificateHow to ignore invalid SSL certificate errors in Guzzle
Cause 1 of 3
PHP has no CA bundle to verify against
1Check
Guzzle's verify option is true by default and uses the default CA bundle of the operating system. Where PHP has none, every HTTPS request fails.
php -r "echo ini_get('openssl.cafile'), PHP_EOL;"2Fix
Download a CA bundle (Guzzle's docs link the one cURL's maintainer publishes) and set openssl.cafile in php.ini to its path. Restart the web server or PHP-FPM afterwards. This fixes every request without a code change.
; php.ini
openssl.cafile=/etc/ssl/certs/ca-bundle.pem3Verify
Run a request through Guzzle with no verify option.
php -r "require 'vendor/autoload.php'; echo (new GuzzleHttp\Client)->get('https://example.com')->getStatusCode(), PHP_EOL;"Confirmed by docs.guzzlephp.org
Cause 2 of 3
The server uses a private or self-signed certificate authority
1Check
Verify accepts a string path to a CA bundle, so PHP can be told to trust a specific certificate.
openssl s_client -connect internal.example.com:443 -showcerts </dev/null2Fix
Pass the path of the CA certificate for that client, so verification stays on.
$client = new GuzzleHttp\Client([
'verify' => '/path/to/internal-ca.pem',
]);
$client->request('GET', 'https://internal.example.com/');3Verify
The request now returns a status code instead of throwing.
php -r "require 'vendor/autoload.php'; echo (new GuzzleHttp\Client(['verify' => '/path/to/internal-ca.pem']))->get('https://internal.example.com/')->getStatusCode();"Confirmed by docs.guzzlephp.org
Cause 3 of 3
You only need it off for a local test
1Check
The Guzzle docs mark disabling validation as insecure and label the example do not do this.
grep -rn "'verify'" app/ src/ 2>/dev/null2Fix
If you must, switch the check off only for that client in a development environment, and remove it before shipping.
$client = new GuzzleHttp\Client([
'verify' => getenv('APP_ENV') !== 'local',
]);3Verify
Search the code base for any verify => false before a release.
grep -rn "verify.*false" app/ src/ 2>/dev/nullConfirmed by docs.guzzlephp.org
How do I stop it coming back?
- Keep one CA bundle path in php.ini on every server instead of per-call options.
- Never ship verify => false; treat a grep hit in code review as a bug.
- Add your internal CA to the machine's trust store, so tools other than PHP agree.
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
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack 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 fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix