PHP致命错误无法打开所需的文件 [英] PHP Fatal Error Failed opening required File

查看:201
本文介绍了PHP致命错误无法打开所需的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Apache收到以下错误

I am getting the following error from Apache

[2011年3月19日星期六23:10:50] [警告] mod_fcgid:stderr:PHP致命错误:require_once()[function.require]:无法打开所需的'/common/configs/config_templates.inc. 158行上/home/viapi​​cs1/public_html/common/configs/config.inc.php中的php'(include_path ='.:/usr/share/pear:/usr/share/php')

我绝对不是Apache的专家,而是config.inc.php&文件. config_templates.inc.php在那里.我还尝试导航到放置在common/configs/中的test.html页面,因此我假设没有权限问题.我还在config_templates.inc.php上设置了权限,以赋予所有人读取,写入和执行权限.不知道此时该怎么办,我检查是否有一个/usr/share/php目录,但我发现那里没有,但是当我执行yum install php时,它说它具有最新版本.有想法吗?

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?

推荐答案

这实际上不是与Apache相关的问题.甚至没有与PHP相关的代码. 要了解此错误,您必须将虚拟服务器上的路径与文件系统中的路径区分开.

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运算符可处理文件.但是没有

require operator works with files. But there is no

                          /common/configs/config_templates.inc.php

服务器上的

文件,而

file on the server, but rather

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

/home/viapics1/public_html

part称为 Document root ,它将虚拟世界与真实世界连接起来.幸运的是,Web服务器通常在与PHP共享的配置变量中具有文档根目录.因此,如果您将代码更改为类似的

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

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

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

it will work from any file placed in any directory.

更新:最终,我写了一篇文章,解释了文件中相对路径和绝对路径之间的差异系统和Web服务器上,详细说明了此问题,并包含一些实用的解决方案.

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.

不幸的是,当您从命令行运行脚本时,这种方便的变量不存在.在这种情况下,将采取一种称为单个入口点"的技术.您也可以参考上面的文章以了解详细信息.

Unfortunately, such a handy variable doesn't exist when you run your script from a command line. In this case a thechnique called "a single entry point" is to the rescue. You may refer to the article above for the details as well.

这篇关于PHP致命错误无法打开所需的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆