0

We are having two domains ( both https ): one as main domain https://dev.project.com/ and the other for images https://dev-images.project.com/. The frontpage loads the images just fine, but I'm having this problem with file_get_contents.

ErrorException in Collection.php line 228:
file_get_contents(): Unable to locate certificate CN
in Collection.php line 228
at HandleExceptions->handleError('2', 'file_get_contents(): Unable to locate certificate CN', '')
at file_get_contents('https://dev-images.project.com/images/12012_resized.jpg') in Collection.php line 228

The file itself exists and opens when checked in browser. I checked this solution, but all the tests are positive:

openssl: yes
http wrapper: yes
https wrapper: yes
wrappers: array (size=12) ...

php.ini

extension=php_openssl.dll
allow_url_fopen = On

The certificate is locally generated and set in php.ini

curl.cainfo = "D:\wamp64\cacert.pem"

My dev station has wamp64 server on Window10 with Php 5.6. Site is based on Laravel5.

Community
  • 1
  • 1
Peon
  • 7,902
  • 7
  • 59
  • 100

1 Answers1

1

Try to passing the path to your cafile like this.

$opts=array(
    "ssl"=>array(
        "cafile" => "D:\\wamp64\\cacert.pem",
        "verify_peer"=> true,
        "verify_peer_name"=> true
    )
);

file_get_contents($url,false,stream_context_create($opts));

edit: if this fails only in your local server, check if you have you added your locally created SSL cert in cacert.pem in your local server and that it contains no errors or extra lines.

Peon
  • 7,902
  • 7
  • 59
  • 100
  • I have around 1500 entries like this .. not sure if that's the right thing to do, especially, since this fails only on local Window dev environment, but works fine on Linux production ... – Peon May 06 '16 at 08:00
  • `file_get_contents() expects parameter 3 to be resource, array given` – Peon May 06 '16 at 08:03
  • this fails only in your local server? have you added your locally created SSL cert in cacert.pem ? in your local server? –  May 06 '16 at 08:04
  • You could set verify_peer and verify_peer_name to false for your test server but this is a security hole. –  May 06 '16 at 08:11