PHP致命错误无法打开所需的文件

Al *_*azi 51 php path

我从Apache收到以下错误

[Sat Mar 19 23:10:50 2011] [warn] mod_fcgid:stderr:PHP致命错误:require_once()[function.require]:无法打开所需的'/common/configs/config_templates.inc.php'(include_path =' .:/ usr/share/pear:/ usr/share/php')在第158行的/home/viapi​​cs1/public_html/common/configs/config.inc.php

我肯定不是Apache的专家,但文件config.inc.php和config_templates.inc.php在那里.我也尝试导航到我放在common/configs /中的test.html页面,所以我假设没有任何权利问题.我还设置了config_templates.inc.php的权限,以赋予每个人读,写和执行权限.不知道该做什么,我查看是否有/ usr/share/php目录,我发现没有,但是当我做了yum install php时,它说它有最新版本.想法?

You*_*nse 88

这实际上不是Apache相关的问题.甚至不是PHP相关的.要了解tis错误,您必须区分虚拟服务器路径和文件系统路径.

require运算符使用文件.但没有

                          /common/configs/config_templates.inc.php
Run Code Online (Sandbox Code Playgroud)

文件在服务器上,而是

/home/viapics1/public_html/common/configs/config_templates.inc.php
Run Code Online (Sandbox Code Playgroud)

require部分称为"文档根",它将虚拟世界与真实世界连接起来.如果您将代码更改为类似的代码

/home/viapics1/public_html
Run Code Online (Sandbox Code Playgroud)

它可以在任何目录中放置的任何文件中运行.


小智 9

如果您正在运行SELinux,则可能必须使用以下内容授予httpd权限以读取/ home目录:

 sudo setsebool httpd_read_user_content=1
Run Code Online (Sandbox Code Playgroud)


Ber*_*ard 5

你可以用 PHP 常量来修复它__DIR__

require_once __DIR__ . '/common/configs/config_templates.inc.php';
Run Code Online (Sandbox Code Playgroud)

它是文件的目录。如果在包含内部使用,则返回包含文件的目录。这相当于 dirname __FILE__。该目录名称没有尾部斜杠,除非它是根目录。1