Anonymous Anonymous - 1 year ago 154
PHP Question

PHP Fatal Error Failed opening required File

I am getting the following error from Apache

[Sat Mar 19 23:10:50 2011] [warn] mod_fcgid: stderr: PHP Fatal error: require_once() [function.require]: 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 158

I am definately not an expert of Apache but the file config.inc.php & 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. Ideas?

Answer

It's not actually apache related question. nor even PHP related.
You have to distinguish virtual server path from filesystem path.

There are no
/common/configs/config_templates.inc.php
file on the server but rather
/home/viapics1/public_html/common/configs/config_templates.inc.php

if you change your code to something like

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

it will work.
also, if you're sure that templates will always remain the same directory, you can write absolute path this way:

require_once(dirname(__FILE__).'/config_templates.inc.php');

Or since PHP 5.3 you can use __DIR__ instead:

require_once(__DIR__.'/config_templates.inc.php');