If your cURL requests are failing to connect to SSL-enabled (HTTPS) endpoints and you’re seeing an error like:
cURL error: SSL: certificate verification failed
This typically indicates an issue with the cURL CA certificate (cacert.pem) file, either due to a missing file path configuration or an outdated certificate bundle.
This article provides step-by-step instructions for resolving the issue on shared and dedicated Windows hosting environments.
Reason:
This error is usually caused by one of the following:
- The cacert.pem file is missing or outdated.
- The php.ini configuration file does not reference the correct location of the cacert.pem file.
- SSL verification is failing due to improper setup.
Important Note:
As a temporary workaround, you can disable SSL verification using the following PHP cURL setting:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Warning: This method is insecure and not recommended for production environments, as it bypasses SSL certificate validation.
Solution:
For Shared Windows Hosting
- Log in to your Control Panel and navigate to File Manager.
- Locate your php.ini file at the site level.
- Edit your php.ini file and ensure the following line points to the correct path:
curl.cainfo = “D:\PHP\cacert.pem”
- Also, update the following values for consistency:
openssl.cafile = “D:\PHP\cacert.pem” openssl.capath = “D:\PHP\”
- Save the file and test your cURL request again.
For Dedicated Windows Servers
- Connect to your server via RDP (Remote Desktop).
- Navigate to the PHP installation directory. For example:
C:\PHP\
- Open the relevant php.ini file for the PHP version you are using.
- Update the following lines:
curl.cainfo = “C:\PHP\cacert.pem” openssl.cafile = “C:\PHP\cacert.pem” openssl.capath = “C:\PHP\”
- Restart your web server or PHP process for the changes to take effect.
Download the Latest cacert.pem File
If you still face issues, your cacert.pem file might be outdated. Download the latest version from the official cURL site:
- Replace the existing cacert.pem file in your PHP directory.
- Or rename the old file and copy the new one in its place.
- Retry your cURL request.
By ensuring the correct path to the cacert.pem file and keeping it updated, you can resolve most cURL SSL verification errors in Windows-based environments. Avoid disabling SSL verification unless you are testing in a secure, local environment.