SSL error SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

后端 未结 9 1014
走了就别回头了
走了就别回头了 2020-12-01 07:03

After upgrading to PHP 5.6 I get an error when trying to connect to a server via fsockopen()..

The certificate on the server (host) is self-signed

相关标签:
9条回答
  • 2020-12-01 07:41

    In my case, I was on CentOS 7 and my php installation was pointing to a certificate that was being generated through update-ca-trust. The symlink was /etc/pki/tls/cert.pem pointing to /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem. This was just a test server and I wanted my self signed cert to work properly. So in my case...

    # My root ca-trust folder was here. I coped the .crt file to this location
    # and renamed it to a .pem
    /etc/pki/ca-trust/source/anchors/self-signed-cert.pem
    
    # Then run this command and it will regenerate the certs for you and
    # include your self signed cert file.
    update-ca-trust
    

    Then some of my api calls started working as my cert was now trusted. Also if your ca-trust gets updated through yum or something, this will rebuild your root certificates and still include your self signed cert. Run man update-ca-trust for more info on what to do and how to do it. :)

    0 讨论(0)
  • 2020-12-01 07:44

    Firstable, make sure that you Antivirus software doesn't block SSL2.
    Because I could not solve a problem for a long time and only disabling the antivirus helped me

    0 讨论(0)
  • 2020-12-01 07:48

    Have you tried using the stream_context_set_option() method ?

    $context = stream_context_create();
    $result = stream_context_set_option($context, 'ssl', 'local_cert', '/etc/ssl/certs/cacert.pem');
    $fp = fsockopen($host, $port, $errno, $errstr, 20, $context);
    

    In addition, try file_get_contents() for the pem file, to make sure you have permissions to access it, and make sure the host name matches the certificate.

    0 讨论(0)
  • 2020-12-01 07:49

    I faced a similar issue during work with Ubuntu 16.04 by using Docker. In my case that was a problem with Composer, but error message (and thus the problem) was the same.

    Because of minimalist Docker-oriented base image I had missing ca-certificates package and simple apt-get install ca-certificates helped me.

    0 讨论(0)
  • 2020-12-01 07:49

    If you are using macOS sierra there is a update in PHP version. you need to have Entrust.net Certificate Authority (2048) file added to the PHP code. more info check accepted answer here Push Notification in PHP using PEM file

    0 讨论(0)
  • 2020-12-01 07:52

    The problem is in new PHP Version in macOS Sierra

    Please add

    stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
    
    0 讨论(0)
提交回复
热议问题