Search code examples
phpfile-get-contents

PHP "file_get_contents" "Unable to set verify locations"


I already checked this: Why won't zend 2 http verify my ssl cert?

I am still getting this error:

Warning: file_get_contents(): Unable to set verify locations '/var/www/duo-security/id_rsa' '(null)' in /var/www/duo-security/FileRequester.php

I made sure that Apache user can read this file by doing this:

sudo www-data nano /var/www/duo-security/security.pub

This is what I am doing:

  $context = Array
(
[http] => Array
    (
        [timeout] => 10
        [method] => POST
        [header] => Array
            (
                [0] => Date: Tue, 31 Nov 3015 12:40:19 +0530
                [1] => Host: api-xxxxxx.duosecurity.com
                [2] => Authorization: Basic REmQV1o0SEEyLzZFS2FWMDUzUFc6ZmMwZGM5ZDUxOWI4ZjY1ZDI2NTIwYWNmYjhiYTk2N2VlOTI4OTc0OA==
                [3] => Content-Type: application/x-www-form-urlencoded
                [4] => Content-Length: 40
            )

        [content] => username=userid
    )

[ssl] => Array
    (
        [allow_self_signed] => 1
        [cafile] => /var/www/path/security.pub
        [verify_peer] => 1
        [verify_peer_name] => 1
    )

 );

Solution

  • It happens because the path to the certificate file is invalid. Try changing the param "cafile" or make sure the security.pub is a valid certificate.