php 给用户组添加apache文件上传权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14116708/
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
Adding apache to a user group file upload permission
提问by keeg
I have a php script uploading files to a certain folder, currently they are uploading as a 'psacln' group, so that I can delete the files via FTP. This was all working fine when PHP was running as FastCGI, I had to change PHP to run as Apache Module in order to get a php extension to work. But now I can't delete files via PHP script because permission is denied. I assume because now the group 'Apache' is trying to delete the file that belongs to 'psacln'. How do I allow apache to delete those files?
我有一个 php 脚本将文件上传到某个文件夹,目前它们正在作为“psacln”组上传,以便我可以通过 FTP 删除文件。当 PHP 作为 FastCGI 运行时,这一切正常,我不得不将 PHP 更改为作为 Apache 模块运行,以使 php 扩展正常工作。但是现在我无法通过 PHP 脚本删除文件,因为权限被拒绝。我假设是因为现在“Apache”组正试图删除属于“psacln”的文件。我如何允许 apache 删除这些文件?
EDIT: ls -alF
编辑:ls -alF
drwxr-xr-x 2 fugitiveink psacln 4096 Nov 13 14:05 92/
drwxr-xr-x 2 fugitiveink psacln 4096 Nov 13 06:57 93/
drwxr-xr-x 2 fugitiveink psacln 4096 Nov 13 14:12 95/
drwxr-xr-x 2 fugitiveink psacln 4096 Dec 21 18:56 96/
drwxr-xr-x 2 fugitiveink psacln 4096 Dec 21 08:30 97/
drwxr-xr-x 2 fugitiveink psacln 4096 Nov 13 14:26 98/
drwxr-xr-x 2 fugitiveink psacln 4096 Nov 13 14:28 99/
回答by hafichuk
I assume that you have shell and root access to this system. If so, you can try adding the apache user (typically apacheor www-data) to the /etc/groupfile.
我假设您对这个系统有 shell 和 root 访问权限。如果是这样,您可以尝试将 apache 用户(通常为apache或www-data)添加到/etc/group文件中。
The proper way to do this is to use usermod, though I typically just edit the file directly.
正确的方法是使用usermod,尽管我通常只是直接编辑文件。
In short if your apache user is apache, try:
简而言之,如果您的 apache 用户是apache,请尝试:
sudo usermod apache --append --groups psacln
This basically gives the apache user access to any files & directories that are owned by the psacln group.
这基本上使 apache 用户可以访问 psacln 组拥有的任何文件和目录。
If this doesn't work, post an example of your directory with the file permissions (ls -alF) and we can work from that.
如果这不起作用,请发布一个具有文件权限 ( ls -alF) 的目录示例,我们可以从中工作。
EDIT:
编辑:
To directly edit the groups file using nano (substitute with whichever editor you're comfortable with):
要使用 nano 直接编辑组文件(用您喜欢的任何编辑器替换):
sudo nano /etc/groups
and find the psaclngroup and add the apacheuser:
并找到该psacln组并添加apache用户:
psacln:x:130:apache
Note that the gid (130) will undoubtedly be different.
请注意,gid ( 130) 无疑会有所不同。
回答by Philip Aylesworth
Set the permissions on the upload directory to 777 (wrx for all users). Can you still upload new files? If you can, you should be able to delete files.
将上传目录的权限设置为 777(所有用户的 wrx)。你还能上传新文件吗?如果可以,您应该能够删除文件。

