php fatal error require once failed opening required
Fatal error: require_once(): Failed opening required?
Доброго времени суток!
Имеется файл init.php. Его путь:
В init.php имеется строка:
Путь до файла list.php:
Fatal error: require_once(): Failed opening required ‘/var/www/user/data/www/site.ru/ac/include/modules/list.php’ (include_path=’.:/usr/share/php:/usr/share/pear’) in /var/www/user/data/www/site.ru/engine/init.php on line 478
Что вызывает данную ошибку?
Так. Ладно. Решил фейковые адреса использовать и только себе хуже сделал. Давайте с самого начала.
Имеется файл init.php. Его путь:
В init.php имеется строка:
Путь до файла list.php:
Fatal error: require_once(): Failed opening required ‘/var/www/user/data/www/site.ru/ac/include/modules/list.php’ (include_path=’.:/usr/share/php:/usr/share/pear’) in /var/www/user/data/www/site.ru/engine/init.php on line 478
Надеюсь, щас я прояснил свою проблему.
когда вы делаете
в скрипте, находящимся по адресу
фактически вы получаете файл
ведь dirname(__FILE__) получает директорию исполняемого скрипта, если я ничего не путаю. Вы уверены, что этого и добивались?
1.
Имеется файл init.php. Его путь:
/var/www/user/data/www/site.ru/engine/init.php
=> полный путь требуемого файла:
/var/www/user/data/www/site.ru/engine/ac/include/modules/
А файл, по вашим словам лежит в:
/var/www/user/data/www/site.ru/ac/include/modules/ (не хватает engine)
а можно сюда результат команд:
Заодно проверьте регистр расширения файла. Может там PHP, а не php
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?
6 Answers 6
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
only exists on the virtual HTTP server, while there is no such path in the filesystem. The correct filesystem path would be
part 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
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.
Fatal error: require_once():
I’m getting the following error:
Warning: require_once(D:/xampp/htdocs/inc/head.php): failed to open stream: No such file or directory in D:\xampp\htdocs\ecommerce1\index.php on line 3
Fatal error: require_once(): Failed opening required ‘D:/xampp/htdocs/inc/head.php’ (include_path=’.;D:\xampp\php\PEAR’) in D:\xampp\htdocs\ecommerce1\index.php on line 3
I have the following code : located in D:\xampp\htdocs\ecommerce1 Index.php
This is the head.php which is located in D:\xampp\htdocs\ecommerce1\inc
4 Answers 4
So you need to call:
Do this in your index.php.
There are two methods to include files in php
Method 1: include()
The reason behind this is that if the require_once() fails to load a file, then the script execution would stop right there. If you use include() it would just throw an error and would continue execution.
Use require_once() when including PHP(or important server-side) scripts and include() when including template-like files.
Take a look at this example:
Note: It’s good practice to use brackets and treat those functions like functions.
PHP Fatal Error: failed opening required
I have a script called ‘sess-start.php’ which lies in an /include directory within my httpdocs directory.
My site continues to give this error:\
[Fri Mar 25 14:52:24 2011] [error] [client 12.3.3.3] PHP Fatal error: require() [function.require]: Failed opening required ‘/includes/sess-start.php’ (include_path=’.:’) in /var/www/vhosts/site.com/httpdocs/page.php on line 4, referer: https://www.site.com/
even though www.site.com/includes DOES exist. What gives!
Edit 1
These are includes/requires which may themselves contain additional require or include statements. Relative paths WILL NOT WORK so please do not suggest such.
Edit 2
Not all of my include or required scripts are contained with a single directory so suggesting to simply place the /includes directory in the include_path is negated as well (and in turn also causes problems on a windows machine)
Update
Perhaps some clarification on a real-life example may help to resolve the issue our team is trying to solve for:
On one page, a user may enter a number of options, the following page makes its necessary calculations and based on that will route the customer in a number of potential options, all which lead to require statements for something like a DB entry.
Then, within the db entry (or some other action) if everything goes smoothly, the member may have chosen before to receive an email confirmation based on his/her action. This require statement lies within the 2nd require (db insert) but is in a different directory than the second and thus causing conflict given the first file treats the linking incorrectly.
Hard coding the absolute path or even setting the appropriate include path per page is ‘ok’ but then it disables our team’s ability to hotlink between files with dreamweaver (or any other program that does the same) because it does not recognize a ‘site root’ when running in a test environment.