Home > Backend Development > PHP Tutorial > How to Resolve the 'SSL3_GET_SERVER_CERTIFICATE: Certificate Verify Failed' Error in PHP?

How to Resolve the 'SSL3_GET_SERVER_CERTIFICATE: Certificate Verify Failed' Error in PHP?

DDD
Release: 2025-01-01 04:38:09
Original
1008 people have browsed it

How to Resolve the

Resolving "SSL3_GET_SERVER_CERTIFICATE: Certificate Verify Failed" Error for HTTPS Requests

In the realm of web development, utilizing HTTPS for secure communication is paramount. However, occasionally, errors may arise during HTTPS requests, such as the infamous "SSL3_GET_SERVER_CERTIFICATE: certificate verify failed, CA is OK."

Navigating the Error

When this error occurs, it typically indicates a discrepancy between the expected server certificate and the one presented by the server. Despite the CA (Certificate Authority) being deemed valid, issues with certificate validation persist.

Resolution via PHP Configuration

For PHP applications, a straightforward solution for this error lies in configuring the curl.cainfo setting within php.ini. This setting specifies the path to a file containing trusted root certificates. By default, PHP uses its own bundled certificates, which may not be updated regularly.

To resolve the error:

  1. Download the ca-certificates bundle from https://curl.se/ca/cacert.pem.
  2. Save the downloaded file to a desired location, e.g., /path/to/cacert.pem.
  3. Open /etc/php.ini, locate the [curl] section, and add the following line:
curl.cainfo = /path/to/cacert.pem
Copy after login
  1. Save and restart the PHP FPM service.

Individual Request Adjustments

If PHP configuration adjustments are not feasible, specific cURL requests can be configured to use the custom CA certificate by setting the CURLOPT_CAINFO option:

curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cacert.pem');
Copy after login

Additional Considerations

Ensure that the server certificate being presented by the HTTPS endpoint is valid and signed by a trusted CA. If the issue persists, consider checking firewall settings or verifying server-side certificates.

Conclusion

By following these steps, you can effectively resolve the "SSL3_GET_SERVER_CERTIFICATE: certificate verify failed, CA is OK" error and ensure smooth HTTPS communication in your PHP applications.

The above is the detailed content of How to Resolve the 'SSL3_GET_SERVER_CERTIFICATE: Certificate Verify Failed' Error in PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template