"Cannot open required file, PHP encountered fatal error"
P粉345302753
P粉345302753 2023-08-20 17:22:12
0
2
556
<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>
P粉345302753
P粉345302753

reply all(2)
P粉662802882

If you are running SELinux, you may need to give httpd permission to read the /home directory, use the following command:

sudo setsebool httpd_read_user_content=1
P粉251903163

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.

The

require operator is used for files. But a path like this

/common/configs/config_templates.inc.php

Only exists on the virtual HTTP server, and there is no such path in the file system. The correct file system path should be

/home/viapics1/public_html/common/configs/config_templates.inc.php

in

/home/viapics1/public_html
The

section 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

require_once $_SERVER['DOCUMENT_ROOT'].'/common/configs/config_templates.inc.php';

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template