简体   繁体   English

PHP无法打开包含文件

[英]PHP unable to open include file

I have a problem with a PHP script. 我的PHP脚本有问题。 The following error is being logged whenever the site is accessed: 每当访问该网站时,都会记录以下错误:

[Fri Sep 26 11:57:56 2014] [error] [client 31.22.44.2] 
PHP Fatal error:  require_once(): Failed opening required
 './sites/default/modules/views/handlers/views_handler_field_markup.inc' 
(include_path='.:/usr/share/php:/usr/share/pear') in 
/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes/handlers.inc
 on line 76

I have confirmed that the file referenced is present, and that www-data can access it. 我已经确认引用的文件存在,并且www-data可以访问它。 Permissions look fine and have not been changed as far as I am aware 权限看起来不错,据我所知尚未更改

What am I missing? 我想念什么?

[Fri Sep 26 11:57:56 2014] [error] [client 31.22.44.2] PHP Fatal error: require_once(): Failed opening required [2014年9月26日星期五11:57:56] [错误] [客户端31.22.44.2] PHP致命错误:require_once():需要打开失败
'./sites/default/modules/views/handlers/views_handler_field_markup.inc' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes/handlers.inc on line 76 /var/www/www.xoomtalk.com/中的'./sites/default/modules/views/handlers/views_handler_field_markup.inc'(include_path ='。:/ usr / share / php:/ usr / share / pear')第76行的htdocs / sites / default / modules / views / includes / handlers.inc

Add path /var/www/www.xoomtalk.com/htdocs into your include_path 将路径/var/www/www.xoomtalk.com/htdocs添加到您的include_path

More explains: 更多说明:

your include_path=.:/usr/share/php:/usr/share/pear , means php script will find include file in: current_path, /usr/share/php or /usr/share/pear 您的include_path=.:/usr/share/php:/usr/share/pear ,意味着php脚本将在以下位置找到包含文件:current_path,/ usr / share / php或/ usr / share / pear

when you want to require this file ./sites/default/modules/views/handlers/views_handler_field_markup.inc 当您需要此文件时。/sites/default/modules/views/handlers/views_handler_field_markup.inc

all allowed path are: (current path) /var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes/./sites/default/modules/views/handlers/views_handler_field_markup.inc 所有允许的路径为:(当前路径)/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes /./ sites / default / modules / views / handlers / views_handler_field_markup.inc

(/usr/share/php) /usr/share/php/./sites/default/modules/views/handlers/views_handler_field_markup.inc (/ usr / share / php)/usr/share/php/./sites/default/modules/views/handlers/views_handler_field_markup.inc

(/usr/share/pear) /usr/share/pear/sites/default/modules/views/handlers/views_handler_field_markup.inc (/ usr / share / pear)/usr/share/pear/sites/default/modules/views/handlers/views_handler_field_markup.inc

In these path ,php can't find the file. 在这些路径中,php找不到文件。

in the following file: /var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes/handlers.inc on line 76 在以下文件中:第76行上的/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes/handlers.inc

Change This: 更改此:

'./sites/default/modules/views/handlers/views_handler_field_markup.inc'

to THIS: '/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/handlers/views_handler_field_markup.inc' 到此: '/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/handlers/views_handler_field_markup.inc'

This should do the trick. 这应该可以解决问题。 The problem is, you're using scripts from various directories, but the "root" of the request is the cwd (current working directory) which you can check with: getcwd() (and you're requesting the include relative to the cwd. 问题是,您正在使用来自各个目录的脚本,但是请求的“根”是cwd(当前工作目录),可以使用以下命令进行检查:getcwd()(并且您正在请求对于cwd的include 。

I managed to solve this problem, ended up being nothing to do with permissions or paths, although there was no indication of this in the Apache logs. 我设法解决了这个问题,尽管与Apache日志中没有任何关系,但最终与权限或路径无关。

The problem was that the server was also running AppArmor which for some reason was blocking the Apache process from accessing the files. 问题在于服务器也正在运行AppArmor,由于某种原因,它阻止了Apache进程访问文件。

AppArmor was set to complain rather than enforce mode for testing (command is aa-complain apache2 ) this made everything start working. AppArmor设置为抱怨而不是强制测试模式(命令是aa-complain apache2 ),这使一切开始工作。

Thanks to all contributors for their suggestions. 感谢所有贡献者的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM