Laravel

Fixing 'cURL error 60: SSL certificate problem: unable to get local issuer certificate' in Laravel & Docker


When your Laravel application dispatches an outbound HTTP request using Guzzle or Laravel’s Http facade to an external API (such as Stripe, PayPal, AWS, Mailgun, or an OAuth provider), PHP abruptly halts execution with an unhandled connection exception:

Illuminate\Http\Client\ConnectionException

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see [https://curl.se/libcurl/c/libcurl-errors.html](https://curl.se/libcurl/c/libcurl-errors.html)) for [https://api.stripe.com/v1/charges](https://api.stripe.com/v1/charges)

Or, if your code instantiates GuzzleHttp\Client directly:

GuzzleHttp\Exception\RequestException

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see [https://curl.se/libcurl/c/libcurl-errors.html](https://curl.se/libcurl/c/libcurl-errors.html))

Error 60 (CURLE_SSL_CACERT) means that cURL attempted to initiate a TLS/SSL handshake with the remote server, but PHP’s OpenSSL subsystem could not verify the remote server’s SSL certificate chain against a trusted local Certificate Authority (CA) root store.


Quick Diagnostic Reference

Find your operating environment below to jump directly to the permanent fix:

Environment / Setup Root Cause Jump to Fix
Windows (Native PHP, Laragon, XAMPP, Herd) curl.cainfo and openssl.cafile are undefined in php.ini Fix 1
Docker Container / Laravel Sail Base container image is missing the ca-certificates system package Fix 2
Ubuntu / Debian Production VPS OS root store is outdated, corrupted, or missing intermediate certs Fix 3
Internal Microservice / Self-Signed HTTPS Requesting local domain (.test) without trusting custom root CA Fix 4
Quick Workaround vs. Security Risk Why using withoutVerifying() exposes your application to MITM attacks Fix 5

1. Windows: Configuring cacert.pem in php.ini

Unlike Linux distributions that maintain a system-level trust store, PHP on Windows does not automatically integrate with the Windows OS Certificate Store. If php.ini does not point to a valid bundle of trusted root certificates, every outbound HTTPS request fails.

Step 1: Download the Official Mozilla CA Bundle

Download the official, cryptographically signed root certificate bundle maintained by the cURL project:

  • Direct download URL: https://curl.se/ca/cacert.pem

Save cacert.pem to a permanent location on your machine where your web server has read permissions (e.g., C:\php\extras\ssl\cacert.pem or inside your PHP installation folder).

Step 2: Update php.ini

Find your active configuration file by running:

php --ini

Open your php.ini file in a text editor, search for [curl] and [openssl], and update or add the following two directives using forward slashes (/) or escaped backslashes:

[curl]
; A default value for the CURLOPT_CAINFO option.
curl.cainfo = "C:/php/extras/ssl/cacert.pem"

[openssl]
; The location of a Certificate Authority (CA) file on the local machine
openssl.cafile = "C:/php/extras/ssl/cacert.pem"

Step 3: Restart Your Web Server / PHP Process

For changes to take effect in web requests, restart your PHP runtime:

  • If using Nginx / Apache: Restart the service.
  • If using Laravel Herd: Restart Herd services via the menu bar.
  • If using php artisan serve: Stop the terminal process (Ctrl + C) and re-run php artisan serve.

2. Docker Containers & Laravel Sail

When running Laravel inside minimal Docker base images (such as Alpine Linux or bare Debian/Ubuntu container builds), the system CA certificate package is often omitted or out of date.

The Fix for Dockerfiles

Add ca-certificates and update-ca-certificates to your container build instructions:

# For Debian / Ubuntu base images:
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    && update-ca-certificates \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# For Alpine Linux base images:
RUN apk add --no-cache ca-certificates && update-ca-certificates

The Fix for Laravel Sail

If you are developing locally with Laravel Sail, force Docker to update the packages inside your application container:

./vendor/bin/sail root-shell
apt-get update && apt-get install -y ca-certificates && update-ca-certificates
exit

To make this change permanent across container rebuilds, rebuild your Sail image without using stale local cache:

./vendor/bin/sail build --no-cache
./vendor/bin/sail up -d

(Note: If restarting your Docker containers resets your database port bindings or leads to host resolution crashes, consult our guide on Fixing SQLSTATE[HY000] [2002] Connection Refused in Laravel).


3. Ubuntu & Debian Production Servers

On production Linux servers, cURL uses the certificates stored in /etc/ssl/certs/ca-certificates.crt. If an upstream Certificate Authority revokes or expires an older root cert (such as the legacy Let’s Encrypt DST Root CA X3 expiration), cURL will fail even if modern browsers show the certificate as valid.

Refresh the server’s certificate store from the terminal:

# 1. Update the ca-certificates package
sudo apt-get update
sudo apt-get --only-upgrade install ca-certificates -y

# 2. Rehash and regenerate the local certificate bundle
sudo update-ca-certificates --fresh

# 3. Restart PHP-FPM so workers read the updated bundle into memory
sudo systemctl restart php8.3-fpm

(Note: Always verify that systemctl status php8.3-fpm shows active workers after restarting. If your site throws a 500 error after restarting the daemon, check Fixing storage/logs/laravel.log Permission Denied in Linux & Docker to ensure worker ownership hasn’t shifted).


4. Internal Microservices & Self-Signed Certificates (.test Domains)

If your Laravel application communicates with an internal microservice, mock API, or local staging server running on a custom .test or .internal domain with a self-signed SSL certificate, cURL will reject it because the issuer is not in public CA registries.

Safe Option: Trust the Custom Root CA in Laravel

Instead of disabling SSL verification globally, supply the path to your internal CA certificate specifically for that outbound client:

use Illuminate\Support\Facades\Http;

$response = Http::withOptions([
    'verify' => storage_path('certs/internal-ca.crt'),
])->post('[https://auth-service.test/api/v1/tokens](https://auth-service.test/api/v1/tokens)', [
    'client_id' => config('services.auth.id'),
]);

5. Why You Must NEVER Use withoutVerifying() in Production

You will often see answers online suggesting you bypass the error by chaining withoutVerifying() or passing ['verify' => false]:

// ❌ CRITICAL SECURITY VULNERABILITY IN PRODUCTION
$response = Http::withoutVerifying()->post('[https://api.stripe.com/v1/charges](https://api.stripe.com/v1/charges)', $payload);

The Man-in-the-Middle (MITM) Risk

Setting verify => false disables certificate validation entirely. When certificate verification is disabled:

  1. Any attacker on the local network, rogue router, or compromised DNS resolver can intercept your request.
  2. The attacker presents their own fake certificate, which cURL will blindly accept without warning.
  3. Your sensitive API keys, customer credit card tokens, and proprietary payloads are transmitted directly to the attacker in plaintext.

Always fix the root certificate bundle on the operating system or inside php.ini rather than disabling verification in your application code.


Verification: Test cURL from the CLI

Run this one-line command in your terminal to verify that PHP’s cURL extension can successfully complete an HTTPS handshake:

php -r "var_dump(file_get_contents('[https://curl.se](https://curl.se)'));"

If the command outputs string data rather than a warning, your SSL bundle is working correctly.

Next, verify via Laravel Artisan Tinker:

php artisan tinker
Http::get('[https://www.google.com](https://www.google.com)')->status();
// Expected output: 200

If Tinker returns 200, your application can securely communicate with all external APIs without triggering cURL error 60.