PHP include or require refuses an http:// address (allow_url_include=0)
Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0Short answer
PHP blocks include, require, include_once and require_once from loading a URL, because allow_url_include is off by default. The normal fix is to include the file by its path on disk. If you truly need a remote file, set allow_url_include in php.ini (it needs allow_url_fopen on too) and restart PHP.
Fix it fast
1Find out which cause you have
Print the two settings that control URL wrappers, and look at the path in the failing include line.
php -r 'var_dump(ini_get("allow_url_include"), ini_get("allow_url_fopen"));'2Match what you see, then jump to its fix
- 1
The failing line looks like require_once 'http://example.com/config.php'A URL is used where a file path on the server was meantFix - 2
The file lives on a different host and a local copy is not an optionYou really need to include code from another serverFix - 3
You set allow_url_include = On and the warning still says allow_url_include=0You changed a php.ini that PHP does not loadFix
- 1
What does the error look like?
Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0http:// wrapper is disabled in the server configuration by allow_url_include=0
Cause 1 of 3
A URL is used where a file path on the server was meant
1Check
The manual describes allow_url_include as the switch that lets include and require use URL wrappers. A site address in the path is what triggers it. Often the file sits on the same server.
grep -rn --include=*.php -E "(include|require)(_once)?\s*\(?\s*['\"]https?://" .2Fix
Replace the URL with a path built from the current file location. Including through a path stays inside PHP and does not call your web server.
// before
require_once 'http://example.com/inc/config.php';
// after
require_once __DIR__ . '/inc/config.php';3Verify
Load the page again. The warning disappears and the file runs.
php -l inc/config.phpConfirmed by php.net
Cause 2 of 3
You really need to include code from another server
1Check
allow_url_include is off by default and can only be set system-wide, so ini_set() in your script cannot turn it on. It has been deprecated since PHP 7.4. It also needs allow_url_fopen to be on.
php --ini2Fix
Prefer downloading the file once and including the local copy. If you still need it, set both options in the php.ini your server loads, then restart. Remember that this executes whatever the remote server returns as PHP code.
; php.ini
allow_url_fopen = On
allow_url_include = On3Verify
Restart PHP and read the values back through the web server, not only on the command line.
sudo systemctl reload php8.3-fpmConfirmed by php.net
Cause 3 of 3
You changed a php.ini that PHP does not load
1Check
Command line and web server often read different ini files. The manual lists the order PHP searches, and php --ini shows the file for the CLI. For server modules the file is read only when the web server starts.
php --ini
php -r 'echo php_ini_loaded_file(), PHP_EOL;'2Fix
Edit the file for the SAPI that serves the site (the Loaded Configuration File line in phpinfo() on a temporary page shows it), then restart the web server or PHP-FPM.
sudo systemctl restart apache2
# or, for PHP-FPM with this version number:
sudo systemctl reload php8.3-fpm3Verify
Run phpinfo(INFO_GENERAL) once on a temporary page, check the loaded file, then delete the page.
curl -s https://example.com/info.php | grep -i 'Loaded Configuration File'Confirmed by php.net
How do I stop it coming back?
- Include code by file path, never by URL. Use __DIR__ so the path does not depend on the working directory.
- Fetch remote data with a normal HTTP request and parse it as data, not as PHP code.
- Keep allow_url_include at its default of off.
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
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
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 fix