PHP cURL Error 60: Fix SSL Certificate Problem Fast
PHP cURL error 60 means libcurl could not verify the peer certificate chain, usually because PHP has no CA bundle configured or the server omits an intermediate certificate; fix it by pointing curl.cainfo or CURLOPT_CAINFO at a current cacert.pem and correcting the served chain. Set curl.cainfo=/etc/ssl/certs/cacert.pem and openssl.cafile to the same file in php.ini, restart php-fpm, then verify with php -r and check CURLINFO_SSL_VERIFYRESULT equals 0. Download https://curl.se/ca/cacert.pem, chmod 644, and confirm with openssl verify -CAfile cacert.pem fullchain.pem; PHP 8.1/8.2/8.3 and libcurl 7.81+ all report this as CURLE_PEER_FAILED_VERIFICATION (60). Do not ship CURLOPT_SSL_VERIFYPEER=false or CURLOPT_SSL_VERIFYHOST=0 as a fix; that disables RFC 5280 path validation and exposes PHP applications to MITM attacks. If curl CLI works but PHP cURL error 60 persists, compare php -i | grep curl.cainfo with curl -V; PHP-FPM, CLI, Composer, and Docker often use different CA bundle paths.
What Is PHP cURL Error 60 and Why Does It Happen?
So what does PHP cURL error 60 actually mean? The number 60 is libcurl’s CURLE_PEER_FAILED_VERIFICATION — a generic “I could not verify the TLS peer certificate” result. Underneath, the OpenSSL backend records a precise reason, and PHP exposes both layers if you ask:
$ch = curl_init('https://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($ch);
if ($body === false) {
echo curl_error($ch), PHP_EOL; // SSL certificate problem: unable to get local issuer certificate
var_dump(curl_errno($ch)); // int(60) = CURLE_PEER_FAILED_VERIFICATION
var_dump(curl_getinfo($ch, CURLINFO_SSL_VERIFYRESULT)); // int(20) = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
}
Verify code 20 is the most common sighting, but it is not the only one. Reading CURLINFO_SSL_VERIFYRESULT (or running openssl s_client) tells you which failure you actually have, instead of guessing:
| Verify result | OpenSSL constant | Typical curl_error() text |
Real cause |
|---|---|---|---|
| 10 | X509_V_ERR_CERT_HAS_EXPIRED | SSL certificate problem: certificate has expired | Leaf or intermediate past notAfter |
| 18 | X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT | self-signed certificate | Dev/private CA not in the trust store |
| 19 | X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN | self-signed certificate in certificate chain | Internal root not trusted locally |
| 20 | X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY | unable to get local issuer certificate | Missing intermediate or missing CA bundle |
| 21 | X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE | unable to verify the first certificate | Server sent only the leaf |
| 62 | X509_V_ERR_HOSTNAME_MISMATCH | no alternative certificate subject name matches target hostname | SAN list doesn’t cover the host |
Why does the trust path break in the first place? Verification requires an unbroken chain: leaf → intermediate(s) → a root that exists in your local CA store. RFC 8446 §4.4.2 makes the server responsible for sending the intermediates and the client responsible for already trusting the root. Break either half and you get code 20 — a misconfigured origin (forgot the intermediate) looks identical to a PHP install with no CA bundle. To see which half is missing, inspect what the server actually transmits:
# -servername is required for SNI vhosts, otherwise you may probe the wrong cert
openssl s_client -connect example.com:443 -servername example.com -showcerts /dev/null
| openssl x509 -noout -subject -issuer -dates
# Then test the chain against a known bundle
curl -vI https://example.com --cacert /etc/ssl/certs/ca-certificates.crt
Why does PHP fail when the OS trusts the site fine? PHP does not reliably inherit the system store. In php.ini, curl.cainfo and openssl.cafile both default to empty, so libcurl falls back to a compiled-in path that Windows ZIP builds, php:8.3-cli-slim Docker images, and custom compilations often don’t have. Check and fix explicitly:
php -i | grep -E 'curl.cainfo|openssl.cafile' # => "no value => no value" means no bundle configured
# php.ini — install the Mozilla-derived bundle from curl.se, then point both directives at it
curl -sSLo /usr/local/share/cacert.pem https://curl.se/ca/cacert.pem
; curl.cainfo = "/usr/local/share/cacert.pem"
; openssl.cafile = "/usr/local/share/cacert.pem"
Can I just turn verification off? No — that hides the problem rather than fixing PHP cURL error 60. CURLOPT_SSL_VERIFYPEER defaults to true and CURLOPT_SSL_VERIFYHOST defaults to 2; setting them to false/0 disables certificate and hostname checks entirely, which the PHP cURL manual and libcurl’s own security guidance both warn against. Also note VERIFYHOST is ignored while VERIFYPEER is off, so the “fix” silently removes both layers of protection.
How Do You Fix PHP cURL Error 60 Step by Step?
Is the failure in PHP or in the trust store? Prove it before editing php.ini: run curl -vI https://example.com and openssl s_client -connect example.com:443 -servername example.com -showcerts < /dev/null. Verify return code: 0 (ok) means the chain is fine; Verify return code: 20 (unable to get local issuer certificate) confirms a chain or CA-store problem. That distinction matters because php curl error 60 — cURL error 60: SSL certificate problem: unable to get local issuer certificate — is only a symptom.
curl -vI https://example.com
openssl s_client -connect example.com:443 -servername example.com -showcerts < /dev/null
# Look for: Verify return code: 0 (ok)
# Failure example: Verify return code: 20 (unable to get local issuer certificate)
-
Inspect the PHP runtime. The PHP manual lists
curl.cainfoas blank by default, so PHP inherits the system/libcurl trust store unless you override it.php --ini php -i | grep -iE 'curl.cainfo|openssl.cafile|openssl.capath|SSL Version' php -r 'print_r(curl_version());' # Check Loaded Configuration File and the cURL Information block. # PHP 8.2 defaults: curl.cainfo and openssl.cafile are blank; VERIFYPEER=true, VERIFYHOST=2.CLI and FPM often load different ini files, so confirm the SAPI that serves requests.
-
Install a current CA bundle. curl.se’s bundle is Mozilla-derived and updated regularly; keeping the old file lets you roll back if a new bundle breaks an internal CA.
sudo cp /etc/ssl/certs/cacert.pem /etc/ssl/certs/cacert.pem.bak 2>/dev/null || true sudo curl -fsSL https://curl.se/ca/cacert.pem -o /etc/ssl/certs/cacert.pem sudo chmod 644 /etc/ssl/certs/cacert.pem sudo -u www-data test -r /etc/ssl/certs/cacert.pem && echo readable -
Set php.ini and restart PHP.
; php.ini (PHP 8.2 example) curl.cainfo = "/etc/ssl/certs/cacert.pem" openssl.cafile = "/etc/ssl/certs/cacert.pem" sudo systemctl restart php8.2-fpm # Apache mod_php alternative: sudo systemctl restart apache2 php -i | grep -E 'curl.cainfo|openssl.cafile' # Must show the path; a blank value means wrong ini or disabled scan file. -
Override per request if php.ini is locked down.
<?php $ch = curl_init('https://example.com/'); curl_setopt($ch, CURLOPT_CAINFO, '/etc/ssl/certs/cacert.pem'); // absolute path curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // default true curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // default 2 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $body = curl_exec($ch); if ($body === false) { echo curl_error($ch); } curl_close($ch);Use an absolute path readable by the PHP-FPM user, such as
www-data. -
Fix the server chain if php curl error 60 persists for a public site. Per Let’s Encrypt docs,
fullchain.pemcontains the leaf plus intermediate, whilecert.pemcontains only the leaf.# Nginx ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # Apache 2.4.8+ SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
| Symptom | Likely cause | Check | Fix |
|---|---|---|---|
| php curl error 60 only in PHP | curl.cainfo blank or missing |
php -i | grep curl.cainfo |
Set curl.cainfo |
| CLI curl also fails | OS trust store stale | openssl s_client ... |
Update ca-certificates |
| Only some sites fail | Missing intermediate | openssl s_client -showcerts |
Serve fullchain.pem |
Which php.ini and PHP cURL Settings Fix Error 60?
If the message is cURL Error 60: SSL certificate problem: unable to get local issuer certificate, start with curl.cainfo. It is a PHP_INI_SYSTEM setting (default: empty) that accepts an absolute path to a PEM CA bundle; it cannot be changed with ini_set() at runtime. When empty, libcurl falls back to its build-time CA path, which may not exist in containers. Point it at the bundle your distro actually ships—/etc/ssl/certs/ca-certificates.crt on Debian/Ubuntu, /etc/pki/tls/certs/ca-bundle.crt on RHEL-family—and make sure the web user can read it.
# /etc/php/8.3/fpm/php.ini — PHP_INI_SYSTEM, default empty
curl.cainfo = "/etc/ssl/certs/ca-certificates.crt"
openssl.cafile = "/etc/ssl/certs/ca-certificates.crt"
; openssl.capath = "/etc/ssl/certs" # only for a c_rehash-maintained hashed dir
# Verify and reload the SAPI that actually runs your code
php -r 'var_dump(ini_get("curl.cainfo"));'
sudo systemctl reload php8.3-fpm
openssl.cafile and openssl.capath are separate from curl.cainfo and also default to empty. They feed PHP’s OpenSSL stream contexts and functions such as openssl_x509_checkpurpose(). Set openssl.cafile to the same PEM bundle; set openssl.capath only if you maintain a hashed directory with c_rehash (OpenSSL docs).
Per-handle options override php.ini for a single cURL handle. CURLOPT_CAINFO takes an absolute PEM file; CURLOPT_CAPATH takes a hashed certificate directory. Keep CURLOPT_SSL_VERIFYPEER true and CURLOPT_SSL_VERIFYHOST at 2—the secure defaults in the PHP cURL manual and libcurl’s CURLOPT_SSL_VERIFYPEER docs. Disabling them “fixes” error 60 by removing TLS authentication, not by repairing trust.
$ch = curl_init('https://example.com/');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CAINFO => '/etc/ssl/certs/ca-certificates.crt', // absolute PEM path
CURLOPT_SSL_VERIFYPEER => true, // default; keep it
CURLOPT_SSL_VERIFYHOST => 2, // default since libcurl 7.28.1; keep it
]);
$body = curl_exec($ch);
if ($body === false) { error_log(curl_error($ch)); } // cURL Error 60
Environment variables are less deterministic: libcurl checks CURL_CA_BUNDLE, while OpenSSL checks SSL_CERT_FILE and SSL_CERT_DIR. In PHP-FPM, set env[SSL_CERT_FILE] = /etc/ssl/certs/ca-certificates.crt; env[] entries still apply with clear_env=yes, but shell exports do not. Still prefer php.ini for repeatable php curl error 60 fixes.
; /etc/php/8.3/fpm/pool.d/www.conf
env[SSL_CERT_FILE] = /etc/ssl/certs/ca-certificates.crt
; clear_env = yes # default; env[] entries still apply, shell exports do not
Composer and vendor HTTP clients read their own CA settings, so fixing php.ini alone may not fix them. Composer: composer config -g cafile /etc/ssl/certs/ca-certificates.crt and composer config -g capath /etc/ssl/certs. Guzzle: 'verify' => '/etc/ssl/certs/ca-certificates.crt'. Laravel: Http::withOptions(['verify' => '/etc/ssl/certs/ca-certificates.crt'])->get(...).
| Setting | Scope | Default | Accepts | Caveat |
|---|---|---|---|---|
curl.cainfo |
PHP_INI_SYSTEM | empty | absolute PEM file | no ini_set(); restart FPM/Apache |
openssl.cafile |
PHP_INI_SYSTEM | empty | absolute PEM file | independent of cURL |
CURLOPT_CAINFO |
per handle | unset | absolute PEM file | overrides php.ini |
CURL_CA_BUNDLE |
environment | unset | PEM file path | less deterministic in FPM |
How Do You Fix PHP cURL Error 60 in Docker, Windows, and Linux?
The message is always the same: cURL error 60: SSL certificate problem: unable to get local issuer certificate. libcurl reached the host, received the chain, and then failed path validation because no trusted root matched — so the fix is almost never “disable verification”, it is “give PHP a CA bundle”. The quickest triage is one command:
php -r 'var_dump(ini_get("curl.cainfo"), ini_get("openssl.cafile"), curl_version()["ssl_version"]);'
# Both empty is normal: libcurl then falls back to its compiled-in default path.
# Empty AND the file missing on disk = error 60 on the first outbound HTTPS call.
| Platform | Install command | Bundle path | Verify |
|---|---|---|---|
| Debian 12 / Ubuntu 22.04–24.04 | apt-get install -y ca-certificates && update-ca-certificates |
/etc/ssl/certs/ca-certificates.crt |
openssl s_client -CAfile … |
| RHEL 9 / Rocky 9 / Alma 9 / CentOS Stream 9 | dnf install -y ca-certificates && update-ca-trust extract |
/etc/pki/tls/certs/ca-bundle.crt |
openssl s_client -CAfile … |
| Alpine 3.19/3.20 | apk add --no-cache ca-certificates && update-ca-certificates |
/etc/ssl/certs/ca-certificates.crt |
openssl verify -CAfile … |
| Windows (PHP zip build) | Download cacert.pem from curl.se |
C:phpcacert.pem |
php -i | findstr cainfo |
Debian/Ubuntu and the PHP Docker images. Set the path explicitly in a conf.d file rather than editing php.ini, and prefix the filename so it sorts last — PHP loads php.ini first, then conf.d/*.ini alphabetically, and a later assignment silently wins. curl.cainfo defaults to empty in php.ini-production.
FROM php:8.3-fpm
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates
&& update-ca-certificates && rm -rf /var/lib/apt/lists/*
COPY zz-curl-ca.ini /usr/local/etc/php/conf.d/zz-curl-ca.ini
# zz-curl-ca.ini: curl.cainfo=/etc/ssl/certs/ca-certificates.crt
# openssl.cafile=/etc/ssl/certs/ca-certificates.crt
Restart the container, then confirm: php -i | grep -E 'curl.cainfo|openssl.cafile'. For distroless/scratch bases there is no package manager — copy a pinned cacert.pem into the image and pass it per-request with curl_setopt($ch, CURLOPT_CAINFO, '/etc/ssl/cacert.pem').
Alpine and RHEL family. Minimal Alpine images frequently ship without the bundle, so a php curl error 60 surfaces on the first outbound call; add the layer explicitly. On RHEL-family hosts, verify with openssl s_client -connect example.com:443 -CAfile /etc/pki/tls/certs/ca-bundle.crt </dev/null and look for Verify return code: 0 (ok). Put php_admin_value[curl.cainfo] in the PHP-FPM pool if you cannot edit php.ini, then systemctl restart php-fpm.
Windows. Zip builds have no bundle. Save https://curl.se/ca/cacert.pem to C:phpcacert.pem, set extension=curl, curl.cainfo and openssl.cafile to that path, and restart IIS (iisreset) or the Apache/Nginx + php-fpm service.
Corporate TLS inspection. Never swap the Mozilla bundle for only your internal root — that breaks public sites. Append instead, keeping a newline separator between PEM blocks:
cat corporate-root.crt >> /etc/ssl/certs/ca-certificates.crt
openssl verify -CAfile /etc/ssl/certs/ca-certificates.crt server-chain.pem
This preserves public trust (per the Mozilla CA program and curl’s cacert.pem extract) while letting the inspection root validate.
CA Bundle Comparison for PHP cURL Error 60: Which Option Should You Use?
If PHP cURL throws cURL error 60: SSL certificate problem: unable to get local issuer certificate, the certificate itself is usually fine — the bundle PHP trusts simply doesn’t contain the root that signed it. PHP’s cURL extension verifies against curl.cainfo (empty by default, in which case libcurl falls back to its compile-time path), so the question is which bundle you pin there.
System CA store — the sane default on Linux. Debian/Ubuntu and Alpine ship /etc/ssl/certs/ca-certificates.crt; RHEL-family systems use /etc/pki/tls/certs/ca-bundle.crt. It updates with the OS, so long-lived servers with package management get root rotations for free.
# Debian / Ubuntu
sudo apt-get install --reinstall ca-certificates
sudo update-ca-certificates # rebuilds /etc/ssl/certs/ca-certificates.crt
# Alpine
apk add --no-cache ca-certificates && update-ca-certificates
# RHEL / CentOS / Rocky / Fedora
sudo update-ca-trust extract # writes /etc/pki/tls/certs/ca-bundle.crt
curl.se cacert.pem — the portable, pinned option. Per curl’s docs, https://curl.se/ca/cacert.pem is generated from Mozilla’s root program and refreshed regularly. Pin it explicitly; it never updates itself.
sudo curl -fsSL https://curl.se/ca/cacert.pem -o /etc/ssl/certs/cacert.pem
sudo chmod 644 /etc/ssl/certs/cacert.pem
# php.ini (empty by default)
curl.cainfo = /etc/ssl/certs/cacert.pem
# or per request
curl_setopt($ch, CURLOPT_CAINFO, '/etc/ssl/certs/cacert.pem');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // libcurl default: true
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // default 2 since libcurl 7.28.1
# monthly refresh via cron, atomic swap
0 4 1 * * curl -fsSL https://curl.se/ca/cacert.pem -o /etc/ssl/certs/cacert.pem.new && mv /etc/ssl/certs/cacert.pem.new /etc/ssl/certs/cacert.pem
certifi — locate it, don’t assume PHP reads it. python3 -m certifi prints the path (e.g. /usr/lib/python3/dist-packages/certifi/cacert.pem). PHP’s cURL never consults certifi automatically; use it only as a source file or when a framework wires it up for you.
- NGINX / APACHE / TOMCAT / IIS 证书配置 · SSL证书安装
- SSL证书安装服务 · 腾讯云 HTTPS 部署 · 证书过期更新
- APP/小程序 HTTPS · SSL网站加密证书 · CA证书配置
Corporate / private CA — merge, never replace. Drop the root into /usr/local/share/ca-certificates/corp-ca.crt and rerun update-ca-certificates, or pass a separate corp-ca.pem via CURLOPT_CAINFO for internal endpoints only. Keep CURLOPT_SSL_VERIFYPEER = true and CURLOPT_SSL_VERIFYHOST = 2; disabling verification to “fix” error 60 breaks hostname checking and invites MITM. Verify what PHP actually loaded with php -i | grep -i 'curl.cainfo|openssl.cafile'.
| Option | Typical path | Update cadence | Best for | Caveat |
| System store | /etc/ssl/certs/ca-certificates.crt or /etc/pki/tls/certs/ca-bundle.crt | OS package updates | Linux servers | Path differs by distro |
| curl.se cacert.pem | /etc/ssl/certs/cacert.pem | Manual or cron | Windows, Docker, pinned apps | Must refresh yourself |
| certifi | output of python3 -m certifi |
Python package updates | Python-adjacent stacks | Not native to PHP |
| Corporate CA | /etc/ssl/certs/corp-ca.pem | Change management | Internal TLS inspection | Merge, do not replace |
One last trap: the curl.se bundle contains no private roots, so internal endpoints need the corporate CA appended — otherwise error 60 returns the moment you switch bundles.
What Common PHP cURL Error 60 Messages Need Different Fixes?
The integer is almost always the same — 60, CURLE_PEER_FAILED_VERIFICATION — so the actionable part of a php curl error 60 is the OpenSSL text that curl_error() appends after the colon. That string maps 1:1 onto an X509_V_ERR_* constant in the OpenSSL verify documentation, and each constant has a different owner: sometimes the remote server, sometimes your cacert.pem, sometimes file permissions.
Message tail from curl_error() |
OpenSSL code | Real cause | Fix |
|---|---|---|---|
| unable to get local issuer certificate | 20 | Intermediate missing from the served chain, or PHP has no CA bundle | Serve fullchain; set curl.cainfo |
| unable to get issuer certificate | 2 | Server sent the leaf only | Install the intermediate |
| unable to verify the first certificate | 21 | Same — no intermediate to build a path | Same as above |
| certificate has expired | 10 | Leaf past notAfter |
Renew; a new bundle will not help |
| self-signed certificate | 18 / 19 | Private root CA unknown to the client | Add internal CA via CURLOPT_CAINFO |
# 1. How many certs does the server send? 1 = leaf only, 2+ = chain present
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null
| grep -c 'BEGIN CERTIFICATE'
# 2. Validity window and SANs — what error 60 checks first
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null
| openssl x509 -noout -subject -dates -ext subjectAltName
# 3. Can your bundle build a path from that leaf?
openssl verify -CAfile /etc/ssl/certs/cacert.pem -untrusted intermediates.pem leaf.pem
# 4. Error 77: is the bundle readable by the PHP-FPM user, and labelled for SELinux?
sudo -u www-data cat /etc/ssl/certs/cacert.pem >/dev/null && echo readable
ls -Z /etc/ssl/certs/cacert.pem # needs httpd_sys_content_t on RHEL/Fedora
For an expired leaf, renew and reload (nginx -s reload, or systemctl reload apache2) — verify with openssl x509 -in cert.pem -noout -dates. Swapping cacert.pem never fixes code 10.
For self-signed internal services, keep verification on and scope trust to one call: curl_setopt($ch, CURLOPT_CAINFO, '/etc/pki/internal-ca.pem');. Setting CURLOPT_SSL_VERIFYPEER to false disables verification for every HTTPS call in the process, which is how php curl error 60 turns into a silent MITM.
Missing intermediates are a server bug: Nginx wants ssl_certificate fullchain.pem; (leaf plus intermediates, root omitted per Let’s Encrypt docs), Apache 2.4.8+ accepts the same file in SSLCertificateFile, while older 2.2/2.4 releases need SSLCertificateChainFile. If the bundle path is simply unset, add curl.cainfo=/etc/ssl/certs/cacert.pem to php.ini and restart PHP-FPM — check what is active with php -r 'var_dump(ini_get("curl.cainfo"), curl_version()["ssl_version"]);'.
Error 51 is the legacy CURLE_SSL_PEER_CERTIFICATE, deprecated in favour of 60 in libcurl 7.62.0, so older builds report the identical php curl error 60 root causes under a different number. Hostname mismatches also land on 60: keep CURLOPT_SSL_VERIFYHOST at 2 and make sure the requested host matches a subjectAltName entry per RFC 6125, not the deprecated CN.
How Do You Verify That PHP cURL Error 60 Is Fixed?
You fix php curl error 60 by proving two things at once: that libcurl now trusts the chain, and that the PHP process actually loaded the CA bundle you configured. One command can do the first part — run this smoke test from the same SAPI (CLI or FPM) that failed before:
php -r '$ch=curl_init("https://www.google.com");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$r=curl_exec($ch);
var_dump($r !== false, curl_errno($ch), curl_error($ch),
curl_getinfo($ch, CURLINFO_SSL_VERIFYRESULT));'
# expected: bool(true) int(0) string(0) "" int(0)
# int(0) == X509_V_OK; any non-zero value is an OpenSSL verify code
A passing run prints bool(true), int(0), an empty error string, and int(0) for the verify result. curl_errno() returning 60 means CURLE_PEER_FAILED_VERIFICATION — the peer certificate could not be authenticated — per the libcurl error list, so if you still see 60 here the bundle is wrong, not the target site.
Next, confirm the setting is live rather than merely present in a file:
php -i | grep -i 'curl.cainfo' # must show the path you set, not "no value"
php --ri curl # prints cURL Information + SSL Version (e.g. OpenSSL/3.0.13)
If php -i shows no value, PHP is reading a different php.ini (check php --ini for “Loaded Configuration File”), the directive is still commented out, or PHP-FPM was never restarted — FPM caches php.ini at start, so systemctl reload php8.3-fpm is mandatory. Note that CLI and FPM often use separate ini files, which is why a CLI test can pass while the web app still throws error 60.
Then validate the bundle itself, independent of PHP:
curl --cacert /etc/ssl/certs/cacert.pem -vI https://example.com
# look for: "SSL certificate verify ok." and HTTP/2 200
openssl s_client -connect example.com:443 -servername example.com
-CAfile /etc/ssl/certs/cacert.pem -verify_return_error < /dev/null
# look for: Verify return code: 0 (ok)
# chain check for a Let's Encrypt fullchain.pem (leaf + intermediate)
openssl crl2pkcs7 -nocrl -certfile fullchain.pem | openssl pkcs7 -print_certs -noout
openssl verify -CAfile /etc/ssl/certs/cacert.pem -untrusted intermediate.pem leaf.pem # -> OK
Per Let’s Encrypt documentation, fullchain.pem holds the leaf plus intermediate, while chain.pem holds the intermediate alone — serving the wrong one produces an incomplete chain and exactly this verification failure on clients missing the intermediate.
| Check | Command | Pass criteria | What failure means |
|---|---|---|---|
| PHP request | php -r smoke test |
errno 0, verify result 0 | Bundle not loaded or chain broken |
| Active config | php -i | grep curl.cainfo |
Your absolute path | Wrong ini or FPM not reloaded |
| Bundle trust | curl --cacert ... -vI |
“verify ok.” | Stale or truncated CA file |
| Chain | openssl verify |
OK |
Missing intermediate |
Finally, make the fix observable in production: log curl_errno($ch) and CURLINFO_SSL_VERIFYRESULT on every failed call, alert on 60, and record curl_version()['version'] and curl_version()['ssl_version'] so you can correlate outages with PHP, OpenSSL, libcurl, or OS upgrades that rewrite /etc/ssl/certs. Schedule an HTTPS probe (the smoke test above, run by cron) and track the CA bundle’s mtime — a silent update-ca-certificates or a relocated curl.cainfo path is the usual cause of error 60 reappearing.
How Do You Prevent PHP cURL Error 60 in Production?
Preventing a php curl error 60 in production is mostly a configuration-management problem, not a code problem. The failure mode is identical everywhere: PHP inherits libcurl’s compiled-in CA path, that path is missing or stale on the host, and every outbound HTTPS request returns SSL certificate problem: unable to get local issuer certificate. Pin the bundle explicitly instead of trusting the default.
Set both directives in php.ini (they are empty by default in PHP 8.1–8.3, meaning “use libcurl/OpenSSL defaults”), then ship that file via Ansible, Puppet, Chef, or a Docker build step so every host and container gets the same value:
; /etc/php/8.3/fpm/php.ini — PHP 8.3 on Debian 12
curl.cainfo = /etc/ssl/certs/cacert.pem
openssl.cafile = /etc/ssl/certs/cacert.pem
openssl.capath = /etc/ssl/certs
Gate the deploy with a CI job that fails loudly. The first line proves the ini was actually loaded (not shadowed by a conf.d snippet or PHPRC), the second records the exact TLS stack for bug reports:
php -i | grep -E 'curl.cainfo|openssl.cafile'
php -r 'var_dump(curl_version()["version"], curl_version()["ssl_version"]);'
php -r '$c=curl_init("https://example.com"); curl_setopt_array($c,[CURLOPT_RETURNTRANSFER=>1,
CURLOPT_SSL_VERIFYPEER=>true, CURLOPT_SSL_VERIFYHOST=>2]);
var_dump(curl_exec($c)!==false, curl_error($c));'
Refresh the bundle on a schedule, but never overwrite a working file until the new one validates. curl -f makes HTTP 4xx/5xx exit non-zero, so the && chain aborts before mv:
# crontab — Mondays 03:00
0 3 * * 1 root curl -fsSL https://curl.se/ca/cacert.pem -o /etc/ssl/certs/cacert.pem.new
&& chmod 644 /etc/ssl/certs/cacert.pem.new
&& openssl verify -CAfile /etc/ssl/certs/cacert.pem.new leaf.pem
&& mv /etc/ssl/certs/cacert.pem.new /etc/ssl/certs/cacert.pem
On the server side, serve the full chain. Per Let’s Encrypt documentation, fullchain.pem contains the leaf plus the intermediate; cert.pem does not, and clients that lack the intermediate cached will fail. In Nginx use ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;; in Apache use SSLCertificateFile .../fullchain.pem. Audit with openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null | grep -c 'BEGIN CERTIFICATE' — expect 2 or more.
| Platform | System bundle path | Typical libcurl |
|---|---|---|
| Debian/Ubuntu | /etc/ssl/certs/ca-certificates.crt | 7.81–8.5 (OpenSSL 3) |
| RHEL 8/9 | /etc/pki/tls/certs/ca-bundle.crt | 7.61 / 7.76 (OpenSSL 3) |
| Alpine 3.18+ | /etc/ssl/cert.pem | 8.x (LibreSSL or OpenSSL) |
| Windows PHP | none — must set curl.cainfo | Schannel or OpenSSL build |
Keep CURLOPT_SSL_VERIFYPEER => true and CURLOPT_SSL_VERIFYHOST => 2 (both defaults, but commonly disabled in legacy code). For internal services, append your private CA to the bundle or pass a dedicated CURLOPT_CAINFO file per handle. Where identity matters more than revocation, CURLOPT_PINNEDPUBLICKEY (libcurl ≥ 7.39.0, PHP ≥ 7.0.7) pins the SPKI hash. Disabling verification is not a fix — it converts a php curl error 60 into silent, undetected MITM exposure, and RFC 6125 §6.1 requires hostname verification for exactly that reason.
PHP cURL error 60 means libcurl failed to verify the remote TLS certificate chain, usually with the message SSL certificate problem: unable to get local issuer certificate. The common OpenSSL verify code is 20, X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY. It is a trust-path problem, not necessarily an expired certificate.
Download a current bundle with curl -fsSL https://curl.se/ca/cacert.pem -o /etc/ssl/certs/cacert.pem, set curl.cainfo and openssl.cafile to that path in php.ini, and restart PHP-FPM. Then test with a PHP cURL request and confirm CURLINFO_SSL_VERIFYRESULT returns 0. If the site serves an incomplete chain, fix fullchain.pem on the server as well.
The curl CLI and PHP often use different CA bundle paths. The CLI may read /etc/ssl/certs/ca-certificates.crt from the OS, while PHP-FPM reads a php.ini with an empty curl.cainfo. Compare php -i | grep curl.cainfo with curl -V and check which php.ini the FPM pool actually loads.
No. Setting CURLOPT_SSL_VERIFYPEER to false and CURLOPT_SSL_VERIFYHOST to 0 disables certificate and hostname validation, exposing PHP applications to man-in-the-middle attacks. The secure fix is to provide the correct CA bundle with curl.cainfo or CURLOPT_CAINFO, or add the private CA for internal services.
curl.cainfo configures the CA bundle used by PHP cURL, while openssl.cafile configures PHP OpenSSL stream contexts and functions. Both default to empty in php.ini. For consistent behavior, set both to the same PEM bundle such as /etc/ssl/certs/cacert.pem, then restart PHP-FPM or Apache.
No. Error 60 is a generic peer-verification failure. OpenSSL verify code 10 means expired, 18 means self-signed, 20 means unable to get local issuer, and 62 means hostname mismatch. Check CURLINFO_SSL_VERIFYRESULT or run openssl s_client to see the exact code before changing the CA bundle.
For the curl.se cacert.pem bundle, a monthly or weekly refresh is common because it is updated regularly. For OS-managed bundles, apply ca-certificates package updates with your normal patch cycle and run update-ca-certificates or update-ca-trust. Always validate the new bundle with openssl verify before replacing the old file.
本文由 sslgood.com 安全团队基于生产环境实战经验撰写,关键结论均经过技术复核。