2

我遇到了 apache 无法通过 PHP 写入文件(例如,写入 csv 文件)的问题 - 我必须将文件权限更改为 777 并且它可以工作,但它的安全性非常差。我正在尝试使用足够的权限进行写入,可能是 664。出了什么问题?

Apache 正在运行apache,组也是apache. 中的所有文件/var/www/html都归root所有,组是web-content

/var/www/html我可以毫无问题地登录到 FTP 客户端并读取/写入文件。

我创建了一个名为 Intranet 的 ftp 用户,在这里我做了什么:

groupadd web-content
usermod -G web-content intranet
chown root:web-content /var/www/html
chmod o+rx /var/www/html
find /var/www/html -type f -exec chmod 0664 {} \;
find /var/www/html -type d -exec chmod 0775 {} \;

ls -la /var/www/

drwxrwxr-x.  4 root web-content 4.0K Sep  6 16:09 html

当我在 FTP 上上传新文件时。

ls -la /var/www/intranet/

-rw-r--r--.  1 intranet intranet       0 Sep  6 17:42 test
4

1 回答 1

2
7 - owner bits, read/write/execute
5 - group bits, read/execute
5 - everyone else bits, read/execute

由于文件是755,所以只有所有者才有写权限。您让 apache 运行为apache,并且该文件由 拥有root,因此所有者不匹配,您最终没有写入权限。

您可能希望将文件 chownapache:web-content或至少root:web-content并将文件 575 改为,以便组权限匹配。

于 2013-09-06T16:29:09.740 回答