file_get_contents() fails because the https:// wrapper is disabled
Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0Short 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.
Fix it fast
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_fopen2Match what you see, then jump to its fix
What does the error look like?
Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0https:// 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/null2Fix
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 read3Verify
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
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.phpConfirmed by php.net
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
PHP says it cannot find the https wrapper
Warning: fopen(): Unable to find the wrapper "https"
PHP registers the https:// wrapper only when its openssl extension is loaded.
3 causes, each with a fixBack end
PHP include or require refuses an http:// address (allow_url_include=0)
http:// wrapper is disabled in the server configuration by allow_url_include=0
PHP blocks include, require, include_once and require_once from loading a URL, because allow_url_include is off by default.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack 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