Apache CGI脚本不能覆盖它具有完全权限的目录中的文件

在Solaris 10上有一个奇怪的问题。 我有一个cgi脚本(Perl)需要覆盖文件。 我们没有在Apache上运行suexec,所以目标目录有完整的(777)访问权限,以便Apache可以写入。

问题是CGI脚本能够将新文件写入目录,但不能覆盖现有文件。

**Directory permissions for file destination:** drwxrwxrwx 146 myuser white 32768 Jun 2 20:46 dest-dir **File Permissions of file that needs to be over written:** -rw-r--r-- 1 myuser white 0 Jun 2 20:50 cgitestfile 

任何人都知道解决这个简单的解决scheme?

看起来像apache只能覆盖一个文件,如果它拥有它。

-rw-r – r– 1 myuser white 0 Jun 2 20:50 cgitestfile

您只拥有对文件的所有者(myuser)的写权限是以用户myuser身份运行的apache? 或作为apache或www.data或类似的东西? 也许你需要为其他人添加写入权限?

在Solaris 10上,缺省值是apache以User nobodyGroup nobody (检查/etc/apache/httpd.conf UserGroup指令)的方式运行。 鉴于你的例子apache将无法写入到cgitestfile因为它没有写访问权限。

更改所有者: dest-dir组和您希望apache覆盖nobody

我遇到这个由于“SELinux”configuration。 如果SELinux正在运行,您需要明确启用Apache写入文件的function。 要使用它,还需要为那些您授予写权限的目录和文件设置额外的权限。

要确定SELinux是否启用,请执行:

 sestatus 

打开启用cgi写入文件的SE布尔值:

 sudo setsebool -P allow_httpd_anon_write 1 sudo setsebool -P allow_httpd_sys_script_anon_write 1 

然后,最后将文件/目录“SELinux安全上下文types”设置为“系统”读/写文件/目录(您也可以将其设置为“公共”types – Google的“chcon”),执行以下操作:

 sudo chcon -R -t httpd_sys_rw_content_t /some/write/path 

(更改/某些/写入/path到您的path。)