ARTICLE AD BOX
Asked 15 years, 1 month ago
Viewed 563k times
I am getting the following error from Apache:
PHP Fatal error: require_once(): Failed opening required '/common/configs/config_templates.inc.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/viapics1/public_html/common/configs/config.inc.php on line 158I am definitely not an expert of Apache but the file config.inc.php and config_templates.inc.php are there. I also tried navigating to a test.html page I placed in common/configs/ so I assume there is no rights issues going on.
I also set the rights on config_templates.inc.php to give everyone read, write, and execute rights. Not sure what to do at this point, I checked to see if there was a /usr/share/php directory and I found there was not but when I did yum install php it said it had the latest.
Any ideas?
It's not actually an Apache related question. Nor even a PHP related one. To understand this error you have to distinguish a path on the virtual server from a path in the filesystem.
require operator works with files. But a path like this
/common/configs/config_templates.inc.phponly exists on the virtual HTTP server, while there is no such path in the filesystem. The correct filesystem path would be
/home/viapics1/public_html/common/configs/config_templates.inc.phpwhere
/home/viapics1/public_htmlpart is called the Document root and it connects the virtual world with the real one. Luckily, web-servers usually have the document root in a configuration variable that they share 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 from any file placed in any directory!
Update: eventually I wrote an article that explains the difference between relative and absolute paths, in the file system and on the web server, which explains the matter in detail, and contains some practical solutions. Like, such a handy variable doesn't exist when you run your script from a command line. In this case a technique called "a single entry point" is to the rescue. You may refer to the article above for the details as well.
8 Comments
Sorry this wasn't it. I updated the code to look like this: <?php require_once($_SERVER['DOCUMENT_ROOT'].'/common/configs/config.inc.php'); and I am still getting the exact same error. Interestingly when I put an X in the url it goes back spells out the entire URL like this: Failed opening required '/home/viapics1/public_htmlX/common/configs/config.inc.php', its all pretty strange, could there be somekind of global override going on? The really strange part is this app was working on another server but when moved to the new one I started having this issue. Thanks so much for the help so far.
2011-03-19T20:07:12.947Z+00:00
[Sun Mar 20 01:53:43 2011] [warn] mod_fcgid: stderr: PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required '/home/viapics1/public_html/photo/common/configs/config.inc.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/viapics1/public_html/photo/index.php on line 2. That directory doesn't exsist. Its trying to go off photo and then to common when it should go to the html root directory and then go into common. I think the code was right and there is some other potential issue going on, perhaps in actually opening the file.
2011-03-19T21:51:27.853Z+00:00
If you have SELinux running, you might have to grant httpd permission to read from /home dir using:
sudo setsebool httpd_read_user_content=1You could fix it with the PHP constant __DIR__
require_once __DIR__ . '/common/configs/config_templates.inc.php';It is the directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname __FILE__ . This directory name does not have a trailing slash unless it is the root directory. 1
1 Comment
For the OP, it won't work. Because it will result in /home/viapics1/public_html/common/configs/common/configs/config_templates.inc.php. The __DIR__ constant is not a magic wand that will solve every single problem with filenames. Like any tool, it must be used with understanding
2023-11-15T11:22:56.663Z+00:00
Run php -f /common/configs/config_templates.inc.php to verify the validity of the PHP syntax in the file.
6 Comments
"The error message makes it clear that file doesn't exist." No it doesn't. That identical error message could result from include path settings, file permissions settings, or safe mode settings. (I was also guessing that it could come from syntax errors, depending on the error reporting settings, but after some testing, it looks like PHP always shows the actual syntax error.)
2011-03-19T19:58:55.473Z+00:00
My error_log includes the stack trace, which contains the same text for these different conditions. E.g., here's a line pulled from my log just now (w/ paths obscured), for a non-existing file: PHP Fatal error: require(): Failed opening required 'sub/include.php' (include_path='.:/usr/local/lib/php') in /path/to/test.php on line 4'' And here's one for an existing file with bad perms: PHP Fatal error: require(): Failed opening required 'sub/include.php' (include_path='.:/usr/local/lib/php') in /path/to/test.php on line 4"'' Ditto for a bad include_path.
2011-03-19T20:56:37.727Z+00:00
Just in case this helps anybody else out there, I stumbled on an obscure case for this error triggering last night. Specifically, I was using the require_once method and specifying only a filename and no path, since the file being required was present in the same directory.
I started to get the 'Failed opening required file' error at one point. After tearing my hair out for a while, I finally noticed a PHP Warning message immediately above the fatal error output, indicating 'failed to open stream: Permission denied', but more importantly, informing me of the path to the file it was trying to open. I then twigged to the fact I had created a copy of the file (with ownership not accessible to Apache) elsewhere that happened to also be in the PHP 'include' search path, and ahead of the folder where I wanted it to be picked up. D'oh!
I was having the exact same issue, I triple checked the include paths, I also checked that pear was installed and everything looked OK (but not using absolute paths) and I was still getting the errors, after a few hours of going crazy looking at this I realized that in my script had this:
include_once "../Mail.php";instead of (it's behavioral equivalence):
include_once ("../Mail.php");Yup, the parenthesis was not missing, but there was no generated error on this line of my script which was odd to me, and a I may have received this in stupid way.
200k55 gold badges455 silver badges870 bronze badges
Explore related questions
See similar questions with these tags.

