"Cannot open required file, PHP encountered fatal error"
P粉345302753
2023-08-20 17:22:12
<p>I get the following error from Apache: </p>
<p><strong>[Sat Mar 19 23:10:50 2011] [warn] mod_fcgid: stderr: PHP fatal error: require_once() [function.require]: Opening '/common/configs/config_templates.inc. php' failed (include_path='.:/usr/share/pear:/usr/share/php') at line 158 of /home/viapics1/public_html/common/configs/config.inc.php </strong> </p>
<p>I'm definitely not an expert on Apache, but the config.inc.php and config_templates.inc.php files are both there. I also tried navigating to the test.html page I placed under the common/configs/ directory, so I don't think there is a permissions issue. I also set the permissions on the config_templates.inc.php file to give everyone read, write, and execute permissions. Not sure what to do, I checked if there was a /usr/share/php directory and found that there wasn't one, but when I installed php using yum, it said it was already the latest version. Any suggestions? </p>
If you are running SELinux, you may need to give httpd permission to read the /home directory, use the following command:
This is not actually an Apache related question, or even a PHP related question. To understand this error, you must distinguish between paths on the Virtual Server and paths in the Filesystem.
Therequire
operator is used for files. But a path like thisOnly exists on the virtual HTTP server, and there is no such path in the file system. The correct file system path should be
in
Thesection is called the document root, which connects the virtual world to the real world. Fortunately, web servers usually have the document root in a configuration variable shared with PHP. So if you change your code to something like this
It will work in any file in any directory!
UPDATE: Finally I wrote an article explaining the difference between relative and absolute paths on file systems and web servers that explains the problem in detail and includes some practical solutions . For example, when you run the script from the command line, such a convenient variable does not exist. In this case, it can be solved using a technique called "single entry". You can also refer to the above article for more details.