file_get_contents(): Unable to locate certificate CN

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

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.

回答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.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!