How to Resolve \'Problem with the SSL CA Cert\' Error in PHP CURL Despite Disabling Verification?

DDD
Release: 2024-10-20 07:20:02
Original
1048 people have browsed it

How to Resolve

Troubleshooting Ignored CURLOPT_SSL_VERIFYPEER in PHP CURL

Problem:

Users are encountering an issue where HTTPS requests using CURL raise a "Problem with the SSL CA cert" error, despite setting both CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST to false.

Causes and Solutions:

To successfully verify host or peer certificates using CURL, you need to specify alternate certificates with CURLOPT_CAINFO or a certificate directory with CURLOPT_CAPATH.

Additionally:

  • CURLOPT_SSL_VERIFYHOST:

    • Set to 1 to check common name existence in the SSL peer certificate.
    • Set to 2 to check common name existence and match it against the provided hostname.

Suggested Code:

To disable verification for host and peer:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
Copy after login

To enable verification and specify a CA certificate file:

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

Additional Notes:

  • Ensure that the CA certificate file is valid and accessible by the server.
  • The curl.cainfo setting in php.ini can also be used to specify the CA certificate file.
  • Rename /etc/pki/nssdb to /etc/pki/nssdb.old to reset certificate authorities.

Update:

After updating libraries and restarting the system, the issue may resolve itself.

The above is the detailed content of How to Resolve \'Problem with the SSL CA Cert\' Error in PHP CURL Despite Disabling Verification?. For more information, please follow other related articles on the PHP Chinese website!

source:php
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