The error message "SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" typically occurs in PHP when making an HTTPS request and the SSL certificate verification fails. This means that PHP is unable to verify the authenticity of the SSL certificate presented by the remote server during the HTTPS connection.

This error often happens due to one or more of the following reasons:

  1. Missing or Outdated CA Certificates: PHP uses a bundle of Certificate Authority (CA) certificates to verify the SSL certificates of remote servers. If this bundle is missing or outdated, the SSL verification can fail. You can update the CA certificates on your system or server.

  2. Incorrect SSL Configuration: There might be an issue with the SSL configuration on the server hosting your PHP application. It could be using a self-signed or improperly configured SSL certificate.

  3. Firewall or Proxy Interference: If your PHP application is running behind a firewall or proxy, it could interfere with the SSL handshake and cause the verification to fail.

To resolve the "certificate verify failed" issue, consider the following solutions:

  1. Update CA Certificates: Ensure that your system has up-to-date CA certificates. You can download the latest bundle from the cURL website or use a package manager on your server to update the certificates.

  2. Disable SSL Verification (Not Recommended for Production): In some cases, developers disable SSL certificate verification to bypass the error temporarily. However, this is not recommended for production environments as it compromises security. You can disable SSL verification using the following code:

    php
    // Note: This is not recommended for production environments. // Use it only for testing purposes or in development environments with self-signed certificates. $options = [ 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, ], ]; $context = stream_context_create($options); $response = file_get_contents('https://example.com', false, $context);
  3. Check SSL Certificate Configuration: If the server hosting your PHP application is using its SSL certificate, make sure it's properly configured. If it's a self-signed certificate, you might need to import the certificate into your server's certificate store or add it as a trusted certificate in your PHP configuration.

  4. Debug and Logging: Enable error logging and debugging to get more detailed information about the SSL verification failure. Check the PHP error logs and server logs for any additional insights.

It's important to address SSL certificate verification failures properly as they are critical for securing communication over HTTPS. Always prefer using a valid and trusted SSL certificate, and avoid disabling SSL verification in production environments.

Have questions or queries?
Get in Touch