Unable to find the wrapper "https" with file_get_contents
Asked Answered
S

9

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?

Schiedam answered 5/9, 2013 at 18:36 Comment(5)
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".Ghana
To which URl are you connecting to? Can you open 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.Ovoid
See #5444749 for a decent answer. Read the answers carefully and enable the extension in the appropiate php.ini. Don't forget to restart Apache.Buschi
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.Hofmannsthal
Possible duplicate of #11453987Repertory
J
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.

Jakejakes answered 20/4, 2017 at 7:58 Comment(2)
@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)Jakejakes
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.Museum
M
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

Museum answered 18/8, 2020 at 1:50 Comment(1)
And I also added php directory path into SYSTEM environment variable Path.Humbert
C
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;

Casares answered 14/3, 2019 at 15:20 Comment(2)
Never thought about updating my PATH after updating to x64 php. Thanks buddy.Glazunov
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 @CasaresArratoon
F
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.

Featly answered 26/4, 2019 at 22:15 Comment(0)
F
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);
Fazeli answered 14/5, 2014 at 8:53 Comment(0)
T
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');
Thermomagnetic answered 25/4, 2016 at 15:34 Comment(0)
O
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.

Ovoid answered 8/5, 2014 at 6:53 Comment(0)
C
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.

Contrivance answered 1/1, 2021 at 6:21 Comment(0)
H
0

I had the same problem when I installed php 8 and apache 24. Removed semicolon on both [extension_dir = "ext"] and [extension=openssl] in php.ini file but openssl was still dissabled. Had to set full path to [extension_dir="C:\PHP\ext"]. Then it worked with file_get_contents(https:).

Hersey answered 2/5 at 20:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.