PHP fatal error cannot open required file
P粉470645222
P粉470645222 2023-08-23 19:46:43
0
2
518
<p>I receive the following error from Apache</p> <p><strong>[Sat Mar 19 23:10:50 2011] [WARNING] mod_fcgid: stderr: PHP fatal error: require_once() [function.require]: Unable to open required '/common' /configs/config_templates.inc. php' (include_path='.:/usr/share/pear:/usr/share/php') at /home/viapics1/public_html/common/configs/config.inc.php line 158</strong>< /p> <p>I'm definitely not an Apache expert, but the files config.inc.php and config_templates.inc.php are there. I also tried navigating to the test.html page placed in common/configs/ so I don't think any permission issues are occurring. I also set the permissions on config_templates.inc.php to give everyone read, write, and execute permissions. Not sure what to do at this point, I checked to see if there was a /usr/share/php directory and found that there wasn't, but when I did yum install php it said it had the latest. Have an idea? </p>
P粉470645222
P粉470645222

reply all(2)
P粉683665106

If you are running SELinux, you may have to grant httpd permissions to read data from the /home directory:

sudo setsebool httpd_read_user_content=1
P粉727531237

This is not actually an Apache related issue. Not even PHP related. To understand this error, you must differentiate between paths on the Virtual Server and paths in the Filesystem.

require Operators apply to files. But such a path

/common/configs/config_templates.inc.php

Only exists on the virtual HTTP server, and the path does not exist in the file system. The correct file system path is

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

where

/home/viapics1/public_html
The

part is called the Document Root, which connects the virtual world with the real world. Fortunately, web servers usually place 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 can be run from any file in any directory!

Update: Finally I wrote an article explaining the difference between relative and absolute paths in files on systems and web servers, explaining the problem in detail and including some practical solutions plan. Like, such a convenient variable doesn't exist when you run the script from the command line. In this case, a technique called "single entry point" can solve the problem. You can also refer to the above article for details.

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