简体   繁体   English

使用PHP mkdir()创建用户组目录时要使用什么chmod权限

[英]What chmod permission to use when creating user group directory with PHP mkdir()

- --

  • A PHP Web application, needs to allow logged in admins to upload and delete images to a web folder, for a particular record. 一个PHP Web应用程序需要允许登录的管理员将图像上载和删除图像到Web文件夹,以用于特定记录。

  • When a record is created in a MySQL database, a folder is also created on the public server - using PHP mkdir() - to hold images for that particular record. 在MySQL数据库中创建记录时,也会在公共服务器上使用PHP mkdir()创建一个文件夹,以保存该特定记录的图像。

  • There will be multiple users of the same application, all needing permission to add and delete images to the folders being created. 同一应用程序将有多个用户,所有用户都需要权限才能向正在创建的文件夹添加和删除图像。

  • The folder would need to continue to be accessible via FTP as well. 该文件夹也需要继续通过FTP进行访问。

So I guess that overall, it needs to be accessible - add, edit, delete, view, FTP - by logged in users, but not accessible to the general public. 因此,我想总的来说,它需要登录用户可以访问-添加,编辑,删除,查看,FTP-但公众不能访问。

What folder permission should I use for this? 我应该为此使用什么文件夹权限?

Reasons why? 原因为何? Security? 安全? Accessibility? 辅助功能? Edit-ability? 可编辑性?

Thanks. 谢谢。 Regards. 问候。

When uploading files using a web interface your upload directory needs to be writable by the apache user. 使用网络界面上传文件时,您的上传目录必须由apache用户可写。 If all interaction with the files are going to be through a web interface, you just need to worry about the apache user, and the other groups would be authenticated via the web application. 如果所有与文件的交互都将通过Web界面进行,则只需担心apache用户,其他组将通过Web应用程序进行身份验证。

If you are creating folders and then allowing users and groups to access the files from the server you need to make the groups. 如果要创建文件夹,然后允许用户和组从服务器访问文件,则需要创建组。 In this case make an admin group. 在这种情况下,请创建一个管理员组。

Steps: 脚步:

//make the admin group
$ groupadd admin

// make the folder for uploads
$ sudo mkdir uploads

// make the apache user (apache or www-data) the owner and the group admin
$ chown apache.admin uploads

// give the folder permission using the sticky bit
// this will allow both apache and admin group to edit/add/delete in uploads
$ chmod 7752 uploads

// the sticky bit will maintain the group inside the uploads folder
// try it out
$ su apache
$ cd uploads
$ mkdir test
$ touch newFile.txt

// the new folder and new file should have admin as the group

Without the sticky bit the new files and folders in uploads will be owned by apache and the apache group. 没有粘性,上传文件中的新文件和文件夹将由apache和apache组拥有。 ie... chmod 775 test 即... chmod 775测试

Now when you make new folders in the uploads folder users that are in the admin group will have ftp access to them 现在,当您在上载文件夹中创建新文件夹时,管理员组中的用户将具有ftp访问权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM