PHP require_once 无法打开流权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1197493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 01:28:57  来源:igfitidea点击:

PHP require_once failed to open stream permission denied

phpcentos

提问by hoyt.dev

I keep getting the error below even after changing the permissions of the folder. I don't know what to do. Not sure why. Any help would be greatly appreciated. I'm working with Cent-os server and this is a php script.

即使在更改文件夹的权限后,我仍然收到以下错误。我不知道该怎么办。不知道为什么。任何帮助将不胜感激。我正在使用 Cent-os 服务器,这是一个 php 脚本。

require_once(mysql_connect.php) [function.require-once]: failed to open stream: Permission denied Date/Time: 7-28-2009 20:09:44

require_once(mysql_connect.php) [function.require-once]:无法打开流:权限被拒绝日期/时间:7-28-2009 20:09:44

采纳答案by hoyt.dev

The problem was not a permission issue. The file I was including was named mysql_connect.php which I think conflicts with either one of mysql's files or functions so the server was confusing my file for that and wouldn't require_once() or include_once() or include() the file. Hence the permission denied fatal error. I change the name of the file and all is well. Thanks to you all for trying to help me out.

问题不是权限问题。我包含的文件名为 mysql_connect.php,我认为它与 mysql 的文件或函数之一发生冲突,因此服务器混淆了我的文件,并且不会 require_once() 或 include_once() 或 include() 文件。因此权限被拒绝致命错误。我更改了文件名,一切正常。感谢大家试图帮助我。

回答by zombat

Things to check:

检查事项:

  • The web server user (often apache) executing the web script needs read ("r") permission on the included file. The web server user is usually different than the user who wrote the files.
  • Check that all the parent directories of the included file have the appropriate execute ("x") permission set.
  • The open_basedirphp.ini setting. If this is configured to be on, you might have a limited set of file opening permissions.
  • Your SELINUX settings.
  • apache执行 Web 脚本的 Web 服务器用户(通常)需要对包含文件的读取 ("r") 权限。Web 服务器用户通常与编写文件的用户不同。
  • 检查包含文件的所有父目录是否都具有适当的执行 ("x") 权限集。
  • open_basedir的php.ini的设置。如果将其配置为开启,则您的文件打开权限可能有限。
  • 您的 SELINUX 设置。