为什么我的 apache 进程不能写入我的世界可写文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/515243/
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
Why can't my apache process write to my world-writeable file?
提问by w43L
I'm having this problem and I reached a deadlock, I would try anything I've reached a deadend. My problem goes like this:
我遇到了这个问题并且陷入了僵局,我会尝试任何已经陷入僵局的事情。我的问题是这样的:
I have a Perl/CGI script installed on Fedora 9 machine running apache2, this script have a config file which placed in the same directory, this config file has 777 permissions.
我在运行 apache2 的 Fedora 9 机器上安装了一个 Perl/CGI 脚本,这个脚本有一个放置在同一目录中的配置文件,这个配置文件有 777 权限。
The script can't write to the file. It can read but in no way could I get it to write to it. The file is owned by the same user the apache is running. I wrote a small PHP script to test and placed it in the same folder. The PHP script can read but can't write to it.
脚本无法写入文件。它可以读取,但我无法让它写入。该文件由运行 apache 的同一用户拥有。我写了一个小的 PHP 脚本来测试并将它放在同一个文件夹中。PHP 脚本可以读取但不能写入。
I'm so desperate here and I don't know where to start with problem, so any help to get me on the right way would be appreciated.
我在这里很绝望,我不知道从哪里开始解决问题,所以任何让我走上正确道路的帮助将不胜感激。
EDIT: I can open the file for editing from command line; it is apache who can't access it
编辑:我可以从命令行打开文件进行编辑;是apache无法访问它
EDIT2: the folder hierarchy /var/www/cgi-bin/script
permissions are like this
/var root 755
www root 755
cgi-bin root 755
script apache 755
EDIT2:文件夹层次结构 /var/www/cgi-bin/script
权限是这样的
/var root 755
www root 755
cgi-bin root 755
script apache 755
EDIT: The problem was in selinux. I disabled it and the script had access to the file thanks for everyone contributed
编辑:问题出在 selinux 中。我禁用了它,脚本可以访问该文件,感谢大家的贡献
Thanks in advance
提前致谢
回答by Douglas Leeder
Does apache run with some selinux profile or similar that prevents it writing in that directory?
apache 是否使用一些 selinux 配置文件或类似配置文件运行以阻止它在该目录中写入?
回答by Philip Reynolds
The user apache probably doesn't have permission to one of the parent directories. It needs to have at least execute permission in all of the directories up to and including the directory that contains your file.
用户 apache 可能没有父目录之一的权限。它至少需要在所有目录中具有执行权限,直到并包括包含您的文件的目录。
EDIT: Right, considering this is a programming site, some code might be in order.
编辑:是的,考虑到这是一个编程站点,可能需要一些代码。
Use the absolute path to the file to test, not the relative one to make sure you're in the right directory.
$! should print out a "Permission Denied" error if it is permissions, can you print out the problem with:
open(FILE, ">/path/to/file/config.ini") || die "Cannot open: $!"; ... close(FILE);
使用文件的绝对路径进行测试,而不是相对路径,以确保您位于正确的目录中。
$! 如果是权限,应该打印出“权限被拒绝”错误,您可以打印出以下问题:
打开(文件,“>/path/to/file/config.ini”) || die "无法打开:$!"; ...关闭(文件);
回答by Nik Reiman
Does the directory allow permission for the webserver to write files there?
该目录是否允许网络服务器在那里写入文件?
回答by Marko
Maybe some other process has a write lock to file? Try lsofto see who is holding it open.
也许其他一些进程对文件有写锁?试试lsof看看是谁在打开它。
回答by converter42
I know that a previous post touched on this, but I think it bears repeating: When discussing a problem of this nature it's helpful to include the relevant code and the output of the exception. If an I/O operation fails, $! should contain the system error message, which would explain why the operation failed. Saying "it didn't work" doesn't really give us anything to go on.
我知道之前的一篇文章谈到了这一点,但我认为有必要重复一遍:在讨论这种性质的问题时,包含相关代码和异常输出是有帮助的。如果 I/O 操作失败,$! 应包含系统错误消息,这将解释操作失败的原因。说“它没有用”并没有真正让我们继续下去。

