19

Calling file_get_contents() with https:// urls give me the following error:

warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?

I've read 10+ SO questions and all of them say to enable extension=php_openssl.dll

I did this and I'm still having issues...

What else could it be?

Jon Gjengset
  • 4,078
  • 3
  • 30
  • 43
John Smith
  • 231
  • 1
  • 3
  • 9
  • We will probably need some more information to help you... I'm assuming you run Windows considering you are trying to load a .dll? Could you try running `phpinfo()` and looking for a line that reads: `OpenSSL support enabled`? Should be under the headline "openssl". – Jon Gjengset Sep 05 '13 at 22:28
  • To which URl are you connecting to? Can you open https://www.namhost.com ? I just found out when trying to connect to the Facebook URL that it spits out a 400 error because the parameters arent correct, which turned out to be my IP address not set correctly in the settings. I.e. I can access HTTPS links, just not the facebook one. – rockstardev May 07 '14 at 10:32
  • 1
    See http://stackoverflow.com/questions/5444249/unable-to-find-the-wrapper-https-did-you-forget-to-enable-it-when-you-config?rq=1 for a decent answer. Read the answers carefully and enable the extension in the appropiate `php.ini`. Don't forget to restart Apache. – GuyT May 07 '14 at 11:56
  • 1
    Can you run `php -i` (cli) or `phpinfo()` (web) to see if the extension is actually enabled? Please post the results if you don't know how to see if it's enabled. – Jasper N. Brouwer May 08 '14 at 19:39
  • Possible duplicate of http://stackoverflow.com/questions/11453487/xampp-and-file-get-contentshttps – Community May 14 '14 at 07:57

8 Answers8

26

SOLVED

To solve this error, you need to install the OpenSSL package for PHP on your webserver.

On a FreeBSD server, you may need to install the following package: php53_openssl and restart your webserver.

On a Windows server, open your php.ini config file and simply uncomment the following line:

 ;extension=php_openssl

and restart the webserver. The error should be resolved.

Reference: I leart it from this link which worked for me.., so credit goes to him.

Amit Shah
  • 7,771
  • 5
  • 39
  • 55
  • @RanjithAlappadan, did you mean uncomment? then the character `;` in beginning of the line will make that line comment. removing it will make it uncomment (means parsable) – Amit Shah Oct 15 '18 at 09:44
  • 1
    This doesn't work for newer versions of PHP. The the correspondent configuration lines have changed. I posted an answer here with the solution to the current version. – Vitox Aug 18 '20 at 01:51
11

On newer versions of PHP on Windows, the accepted answer won't work.

For PHP 7.x, you need to uncomment (remove the ; at the beginning of the line) the following lines:

extension_dir = "ext"
extension=openssl

Vitox
  • 3,852
  • 29
  • 30
3

For PHP 7 on Windows 64bit be sure to put libcrypto-1_1-x64.dll to the environmental variable path. For example: C:\php\libcrypto-1_1-x64.dll;

Артем
  • 41
  • 6
  • Never thought about updating my PATH after updating to x64 php. Thanks buddy. – Claude Aug 22 '19 at 14:46
  • If you are using WAMP and have different PHP7+ versions installed, you need to manually update the PATH environment variable to the version your are using in WAMP. Thanks @Артем – rtribaldos Nov 26 '19 at 14:08
3

I just wanted to add this tidbit because I struggled for hours with this issue and finally figured out something that works. With a lot of these WAMP/XAMP/MAMP installations, the configuration files are placed in non-standard directories (i.e., C:\MAMP\conf\php\php7.2.10\php.ini). You need to make sure that your php cli has loaded the INI you are modifying.

$ php --ini

If it is not pointing to the correct INI, or loads no configuration file at all, you can change the PHPRC environment variable for the user executing the script to point to the correct location for the INI that you have correctly modified. Also, ensure that the extension_dir parameter in php.ini is contains the correct path to where your extensions are stored.

Hope this helps.

Jack
  • 135
  • 2
  • 12
2

Please ensure if allow_url_include and allow_url_fopen are set to 'On' in php.ini.

Uncomment them if these lines are commented.

Also, you can use the following script for diagnostics: (taken from the accepted answer on How to get file_get_contents() to work with HTTPS?)

$w = stream_get_wrappers();
echo 'openssl: ',  extension_loaded  ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_dump($w);
Community
  • 1
  • 1
Kanishk Dudeja
  • 1,201
  • 3
  • 17
  • 33
1

Like people say, check with the configuration.

phpinfo.php

<?php
phpinfo();
?>

Search for OpenSSL on the webpage. Also, don't forget to restart the WebServer after altering the php.ini file.

If you can't use file_get_contents(), use cURL instead if available, it's better in many ways and faster.

function url($url,$option = null) {

    $cURL = curl_init();

    if ($option) {
        curl_setopt($cURL, CURLOPT_URL, $url.$option);
    } else {
        curl_setopt($cURL, CURLOPT_URL, $url);
    }

    curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($cURL, CURLOPT_AUTOREFERER, 1);
    curl_setopt($cURL, CURLOPT_HTTPGET, 1);
    curl_setopt($cURL, CURLOPT_VERBOSE, 0);
    curl_setopt($cURL, CURLOPT_HEADER, 0);
    curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, 1);
    curl_setopt($cURL, CURLOPT_DNS_USE_GLOBAL_CACHE, 0);
    curl_setopt($cURL, CURLOPT_DNS_CACHE_TIMEOUT, 2);

    $output['page'] = curl_exec($cURL);
    $output['contentType'] = curl_getinfo($cURL, CURLINFO_CONTENT_TYPE);

    curl_close($cURL);

    return $output;

}

$page = url('https://example.com/','i/like/subfolders');
Anuga
  • 2,619
  • 1
  • 18
  • 27
0

I had the same problem. I was trying to access facebook graph. It wasn't that it could not access the URL, it was that Facebook was returning a 400 error because I wasn't passing parameters through. Try connecting to HTTPS on a site that will have a working HTTPS connection. E.g. Try this:

file_get_contents("https://www.namhost.com");

If that works, you must see why the HTTPs connection you are connecting to is failing, because the problem isn't that you can't connect to HTTPs, but rather that what you are connecting to isn't liking the request.

rockstardev
  • 13,479
  • 39
  • 164
  • 296
0

for me, this problem resulted from installing versions of PHP subsequent to 7.1 with apache 2.4.23 on wampserver 3.2.4. All versions of PHP after 7.1 produced the error "Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?" and "Fatal error: SOAP Fault: [HTTP] SSL support is not available in this build".

A significant indicator of the problem was that on phpinfo.php, "Registered Stream Socket Transports" showed only TCP & UDP available, with none of the SSL transports available.

Upgrading to apache 2.4.46b resolved all SSL related problems, and "Registered Stream Socket Transports" subsequently included ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2 & tlsv1.3 transports.

Asok Smith
  • 57
  • 1
  • 2