2.8.2.2. Error "Fatal error: require*(): Failed opening required"

When loading files to include in the current script, the following error may occur:

Fatal error: require*(): Failed opening required ~/example.com/www/example.php in /home/example/example.com/www/somefile.php
  • require*(): — the function used by the script to load the file. Instead of require, you can use require_once, include, etc.
  • Failed opening required ~/example.com/www/example.php — the cause for the error. In this case, the message indicates that the file ~/example.com/www/example.php cannot be found at the specified path or is inaccessible.
  • in /home/example/example.com/www/somefile.php — the file from which the call to another file was made. This information can be useful for debugging.

The most common causes of the error:

  • Missing file. The most common cause is precisely that the file being called is missing. This issue can occur when copying, moving, or performing other actions on site files. Additionally, files may sometimes be deleted either by a user or by the site's own scripts, which can cause this error to occur.
  • Incorrect path to the file being called. If this problem occurs, you should compare the file path specified in the error message with the actual path. It is important to note that paths may contain elements that can cause confusion when determining the path, for example:
    • /./ — current directory. You can simply ignore this, as it has no effect on the path.
    • /../ — parent directory. This is often used in scripts when constructing relative paths. For example, the path example.com/www/include/../vendor/somefile.php is actually the path example.com/www/vendor/somefile.php.
    • In Linux, file and directory names are case-sensitive. For example, if a script attempts to access a file named SomeFile.php, but the file is actually stored in the file system under the name somefile.php, an error will occur stating that the file was not found. Unlike in Windows, SomeFile.php and somefile.php are two different files.
  • Incorrect file permissions. If the file permissions do not allow the group to read the file, it will not be opened by another script. To reset permissions, we recommend using restore default permissions. For proper operation, use permissions 640 for files and 750 for directories.
Teneur

    (1)