Troubleshooting
PHP error when using require_once, require, include_once or include
When PHP cannot open a file requested by require_once, require, include_once or include, the full message shows the requested path, which may be relative, the file that made the call and its line. require stops execution; include usually raises a warning and lets execution continue.
An example message is:
Fatal error: require(): Failed opening required '/home/usuario_cpanel/public_html/fichero.php' (include_path='.:php') in /home/usuario_cpanel/public_html/index.php on line 1
This error shows that PHP could not open the resource requested by require or include. Also keep the preceding warning, because it may specify whether the path, permissions, open_basedir or include_path failed.
In the example, index.php calls fichero.php on line 1. PHP says it could not open it at that path; that does not prove on its own that the file does not exist.
Possible causes and solutions
- Check the exact path in the error, whether the file exists and the upper and lower case of each name.
- Check the
DocumentRootand the actual structure of the deployment. A website does not have to be in/home/usuario/public_htmland may load code located outside the public directory. - Check the file's permissions, the traverse permissions of its parent directories and the owner.
- If the file exists and is readable, check
open_basedirrestrictions,include_path, wrappers and the working directory used for a relative path. - If it has disappeared, compare versions, deployments, backups and logs. Consider an intrusion only when there are changes, access or other evidence to support it.
Stable paths and dependencies
When the file belongs to the same project, a path based on __DIR__ avoids depending on the directory the process runs from:
require __DIR__ . '/config/bootstrap.php';
This is an example: that file must exist in your application's actual structure. If vendor/autoload.php is missing, check how dependencies are deployed with Composer and its lock file; do not create an empty file or replace require with include to hide it. Do not build an include path directly from request data.
You may also find useful
- Maximum execution time of X seconds exceeded in x.php Diagnose what exhausts max_execution_time and raise the limit temporarily and within bounds only whe...
- Debug errors in PHP applications or files Diagnose a blank screen or a 500 error by reproducing the failure and checking the most specific log...
- Enable PHP error logging from cPanel Temporarily enable log_errors for the effective version from cPanel's PHP selector, without showing...
- Enable PHP error logging from the .htaccess file Configure .htaccess to temporarily log PHP errors outside public_html, without revealing them on scr...
Something wrong or out of date? Tell us and we will review it.