Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

file_get_contents() fails because the https:// wrapper is disabled

ErrorWarning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0

Short answer

allow_url_fopen lets PHP functions like file_get_contents() open URLs. When it is off, a remote URL fails with 'https:// wrapper is disabled in the server configuration'. It can only be set in php.ini or the server config, not with ini_set(). Turn it on there, or fetch the URL with cURL instead.

  • Applies to PHP 8.3, PHP 8.4, Ubuntu 24.04, cPanel hosting
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print allow_url_fopen from the PHP that serves your website, not only from the command line.

    php -i | grep allow_url_fopen
  2. 2Match what you see, then jump to its fix

    1. 1The warning names allow_url_fopen=0.allow_url_fopen is off in php.iniFix
    2. 2ini_set('allow_url_fopen', '1') returns false and the warning stays.ini_set() cannot turn it on at runtimeFix

What does the error look like?

  • Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0
  • https:// wrapper is disabled in the server configuration by allow_url_fopen=0

Cause 1 of 2

allow_url_fopen is off in php.ini

1Check

The setting is on by default, so someone switched it off. Its scope is INI_SYSTEM, so it can only be changed in php.ini or the server configuration.

php --ini && grep -rn allow_url_fopen /etc/php/*/ 2>/dev/null

2Fix

Enable it in the php.ini the web server uses, then reload PHP.

; php.ini
allow_url_fopen = On
; then reload PHP-FPM or Apache so the change is read

3Verify

Print the value from a script served by the web server, because the command line can use a different php.ini.

<?php var_dump(ini_get('allow_url_fopen'));

Confirmed by php.net

Did this fix it?

Cause 2 of 2

ini_set() cannot turn it on at runtime

1Check

Because the scope is INI_SYSTEM, a script cannot change it. Check the return value of ini_set().

php -r 'var_dump(ini_set("allow_url_fopen", "1"));'

2Fix

Remove the ini_set() call and change the setting in php.ini, or in the control panel's PHP options if the host manages it. If the host will not allow it, use the cURL extension to fetch the URL.

$ch = curl_init('https://example.com/data.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($ch);
if (curl_errno($ch)) {
    throw new RuntimeException(curl_error($ch));
}
curl_close($ch);

3Verify

The body is returned and no wrapper warning appears.

php fetch.php

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Prefer cURL or an HTTP client library for remote requests, so the code does not depend on allow_url_fopen.
  • Document the php.ini values your app needs in the deployment notes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

CodeIgniter 4 cannot write its cache files

CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/

CodeIgniter 4's file cache needs a cache directory that the web server can really write to.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.