Failed to Open Required File
Fatal error: require(): Failed opening required 'config.php' (include_path='.:/usr/share/php')Quick Answer
PHP cannot find the file you are trying to require. The file path is incorrect, the file does not exist, or the include_path does not contain the file's directory.
Why This Happens
require() and require_once() cause a fatal error when the specified file cannot be found or opened. This is different from include() which only produces a warning. Common causes are incorrect relative paths, missing files, or running the script from a different working directory than expected.
The Problem
require 'config.php'; // Relative path breaks when run from different directoryThe Fix
require __DIR__ . '/config.php'; // Always relative to the current file's directoryStep-by-Step Fix
- 1
Check the file path
Verify the file exists at the exact path specified. Use realpath() or __DIR__ to debug the resolved path.
- 2
Use __DIR__ for reliable paths
Replace relative paths with __DIR__ . '/filename.php' to make paths relative to the current file's directory instead of the working directory.
- 3
Check file permissions
Ensure the PHP process has read permissions on the file. Check ownership and permission bits with ls -la.
Bugsly catches this automatically
Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.
Try Bugsly free