php写入文件权限问题

发布于 2024-12-03 14:49:48 字数 377 浏览 0 评论 0原文

当 php-script 尝试写入文件时:

-rwxr-xr-x.  1 eugene_val eugene_val  8033 Sep 10 10:47 ajax_EN.json

我收到错误:

fopen(ajax_EN.json): failed to open stream: Permission denied

我想知道考虑到安全性,什么是适当的解决方案。 我能想到的选项是:

1)将此文件chown到apache用户并将其chmod到700

2)将apache添加到文件所有者组

3)使用suPHP和likes(我不希望这样做,因为性能)打)

When php-script is trying to write to a file:

-rwxr-xr-x.  1 eugene_val eugene_val  8033 Sep 10 10:47 ajax_EN.json

I get an error:

fopen(ajax_EN.json): failed to open stream: Permission denied

I wonder what could be an appropriate solution to it taking security into consideration.
The options I could think of are:

1) chown this file to apache user and chmod it to 700

2) add apache to a group of the file-owner

3) use suPHP and likes(which I would not like to because of the performance hit)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仙女山的月亮 2024-12-10 14:49:48

更好的选择是将文件的组更改为 Apache 用户组,并将文件设置为组可写:

$ chgrp <apache_group> ajax_EN.json
$ chmod g+w ajax_EN.json

A better choice is to change the file's group to the Apache user group, and set the file to be group-writable:

$ chgrp <apache_group> ajax_EN.json
$ chmod g+w ajax_EN.json
入怼 2024-12-10 14:49:48

该文件的路径的权限也很重要。即使您对文件进行 chmod 777,如果尝试读取该文件的用户没有该路径的读取权限,他们仍然无法读取该文件。

The permissions of the path for this file also matter. Even if you chmod 777 the file, if the user trying to read it doesn't have read permissions for the path, they still won't be able to read the file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文