Ad Space — Top Banner

Warning: include(): Failed opening

PHP Programming Language

Severity: Moderate

What Does This Error Mean?

This warning means PHP tried to include or require a file but could not find it at the path you specified. The file path is wrong, the file does not exist, or PHP does not have permission to read it. The script keeps running after this warning, but the included code never runs — which usually causes more errors immediately after.

Affected Models

  • PHP 5.x
  • PHP 7.x
  • PHP 8.x
  • All PHP versions

Common Causes

  • The file path is wrong — a typo, missing folder, or wrong directory separator
  • The file does not exist at all — it was deleted, renamed, or never created
  • The path is relative and PHP is resolving it from the wrong working directory
  • PHP does not have read permission for the file or folder
  • The include_path in php.ini does not include the directory where the file lives

How to Fix It

  1. Check that the file actually exists at the path you specified. Open your FTP client or file manager and verify.

    A file that was renamed from 'Config.php' to 'config.php' still fails on case-sensitive Linux servers.

  2. Use an absolute path instead of a relative path. Example: require_once __DIR__ . '/includes/header.php';

    __DIR__ always gives you the directory of the current file, no matter how PHP was started. It is the safest way to build paths.

  3. Check file permissions. The file and its parent folders should be readable by the web server user.

    On Linux, a permission of 644 for files and 755 for folders is standard. Use your hosting panel or chmod to adjust.

  4. Double-check the spelling and capitalization of every folder and file name in the path.

    Windows ignores capitalization in paths, but Linux (where most servers run) does not. 'includes/Header.php' and 'includes/header.php' are different on Linux.

  5. Add error reporting to temporarily see the full path PHP is trying to load: echo __DIR__; near the include statement.

    This shows you exactly where PHP is looking, which makes it easy to spot the mismatch.

When to Call a Professional

Failed opening errors are usually a path or permission issue. If you are on a managed server and cannot change file permissions, contact your web host. For complex projects with many includes, a PHP developer can help reorganize the file structure.

Frequently Asked Questions

What is the difference between include and require in PHP?

include() shows a warning if the file is missing but keeps running. require() shows a fatal error and stops the script. Use require() for files that are essential — like database connections or core functions. Use include() for optional files like optional sidebars or widgets.

Why does my include work on Windows but fail on my Linux server?

Windows file paths are case-insensitive. Linux file paths are case-sensitive. A path like 'includes/Config.php' works on Windows even if the file is 'config.php'. On Linux, it fails. Always match the exact capitalization of file and folder names.

What does __DIR__ do in PHP?

__DIR__ is a magic constant that gives the full absolute path to the folder containing the current PHP file. Using it in paths — like __DIR__ . '/config.php' — makes paths reliable and portable. It is the recommended way to build include paths.