PHP站点调用reCAPTCHA API遇cURL error 60问题求助
Hey there, let's work through this frustrating cURL error 60 issue together! You've already tried the basic fix of adding the CA certificate to php.ini, so let's dive into the less obvious checks that might be causing the problem.
Common Troubleshooting Steps to Try
Verify you're editing the correct
php.inifile
It's super easy to modify the wrong configuration file—PHP often uses differentphp.inifiles for CLI and web server requests. Create a quick test file with:<?php phpinfo(); ?>Access it in your browser, then look for the
Loaded Configuration Fileline. Make sure thephp.iniyou edited matches this path.Double-check the
curl.cainfoabsolute path
Ensure the path you entered is a full, valid absolute path (no truncated entries like/var/w...). For example:[curl] curl.cainfo="/var/www/html/cacert.pem"Also, confirm the web server user (like
www-datafor Apache ornginxfor Nginx) has read permissions on the.pemfile. Fix permissions with:chmod 644 /var/www/html/cacert.pem chown www-data:www-data /var/www/html/cacert.pemRestart your web server (and PHP-FPM if using it)
Changes tophp.iniwon't take effect until you restart your web server. For Apache:sudo systemctl restart apache2If you're using Nginx with PHP-FPM, restart both services:
sudo systemctl restart nginx sudo systemctl restart php8.2-fpm # Replace with your PHP versionTest with manual CA certificate setup in code
To rule outphp.iniconfiguration issues, directly set the CA cert path in your reCAPTCHA cURL call:$ch = curl_init("https://www.google.com/recaptcha/api/siteverify"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'secret' => 'YOUR_RECAPTCHA_SECRET', 'response' => $_POST['g-recaptcha-response'] ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CAINFO, "/var/www/html/cacert.pem"); // Full path to your .pem $response = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if ($error) { echo "cURL Error: " . $error; } else { // Process reCAPTCHA response }If this works, it means your
php.inichanges aren't being picked up—go back to verifying the correct file path and restarting services.Update system-level CA certificates
Sometimes system-wide CA certs are outdated. On Ubuntu/Debian:sudo apt-get update && sudo apt-get install --reinstall ca-certificatesOn CentOS/RHEL:
sudo yum reinstall ca-certificatesRestart your web server after updating.
Confirm reCAPTCHA API URL is correct
Ensure you're calling the valid HTTPS endpoint:https://www.google.com/recaptcha/api/siteverify(this works for both v2 and v3 reCAPTCHA). Typos here can also trigger SSL errors.
Give these steps a shot—one of them is almost certainly the fix you need. Let me know if you hit any snags along the way!
内容的提问来源于stack exchange,提问作者Freddy Heppell

