Maaz Zindani

Loading the index…

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

PHP include or require refuses an http:// address (allow_url_include=0)

ErrorWarning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0

Short 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.

  • Applies to PHP 8.3, PHP 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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"));'
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The file lives on a different host and a local copy is not an optionYou really need to include code from another serverFix
    3. 3You set allow_url_include = On and the warning still says allow_url_include=0You changed a php.ini that PHP does not loadFix

What does the error look like?

  • Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0
  • http:// 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.php

Confirmed by php.net

Did this fix it?

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 --ini

2Fix

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 = On

3Verify

Restart PHP and read the values back through the web server, not only on the command line.

sudo systemctl reload php8.3-fpm

Confirmed by php.net

Did this fix it?

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-fpm

3Verify

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

Did this fix it?

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

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 fix

Next step

Want this handled for good?

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