沃梦达 / 编程问答 / php问题 / 正文

PHP致命错误打开所需文件失败

PHP Fatal Error Failed opening required File(PHP致命错误打开所需文件失败)

本文介绍了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.php' (include_path='.:/usr/share/pear:/usr/share/php') 在/home/viapi​​cs1/public_html/common/configs/config.inc.php 第 158 行

我绝对不是 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 a path like this

                          /common/configs/config_templates.inc.php

只存在于虚拟HTTP服务器上,而文件系统中没有这样的路径.正确的文件系统路径是

only 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.php

哪里

/home/viapics1/public_html

部分称为文档根,它将虚拟世界与真实世界连接起来.幸运的是,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 this

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

它适用于放置在任何目录中的任何文件!

更新:最终我写了一篇文章,在文件中解释了相对路径和绝对路径之间的区别系统和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. 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.

这篇关于PHP致命错误打开所需文件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP致命错误打开所需文件失败

基础教程推荐