Linux 在 var/www/image 目录中启用写权限 Ubuntu Server
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9181254/
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
Enabling write permissions Ubuntu Server in var/www/image directory
提问by re1man
I'm trying to get my php test upload script to work and was wondering what the command would be to allow files to be uploaded in ubuntu server in the var/www/image directory
我正在尝试让我的 php 测试上传脚本工作,并且想知道允许将文件上传到 ubuntu 服务器中 var/www/image 目录的命令是什么
采纳答案by alain.janinm
cd /var/www/image
For file like image you don't need execution permission :
对于像图像这样的文件,您不需要执行权限:
sudo chmod 664 *
If you have directories inside image and you want to apply permission :
如果您在图像中有目录并且想要申请权限:
sudo find . -type d -exec chmod 755 "{}" \;
This will recursively search your directory and chmod 755 all directories only.
这将仅递归搜索您的目录和 chmod 755 所有目录。
Similarly, the following will chmod all files only (and ignore the directories):
类似地,以下将仅 chmod 所有文件(并忽略目录):
sudo find . -type f -exec chmod 644 "{}" \;
File name with space case (thanks to Nicklas B)
带空格的文件名(感谢 Nicklas B)
find . -type f -print0 | xargs -0 chmod 644
回答by Joe
cd /var/www
cd /var/www
sudo chmod 775 image
sudo chmod 775 image
You'll be prompted to enter the admin password - do so, and hit [return].
系统会提示您输入管理员密码 - 这样做,然后点击 [return]。
回答by CXJ
What username will be uploading the files? Usually on Ubuntu the Apache web server username is www-data. You can check for sure by finding the web server process in a process list command and seeing which username under which it is running.
上传文件的用户名是什么?通常在 Ubuntu 上,Apache Web 服务器用户名是www-data。您可以通过在进程列表命令中查找 Web 服务器进程并查看它在哪个用户名下运行来确定。
ps aux | grep apache
or ps aux | grep httpd
should give you that answer.
ps aux | grep apache
或者ps aux | grep httpd
应该给你那个答案。
Then you will usually want to make that Apache username the owner of the directory and all files and directories within it:
然后,您通常希望将该 Apache 用户名设为目录及其中所有文件和目录的所有者:
cd /var/www/image
# recursively (all subdirs & files) set owner to www-data for current directory
chown -R www-data .
Ordinarily, the above should be enough, but if for some reason the directory, files or subdirectories do not have write permission for the owner username, that's easily fixed by changing the permissions to add that write access, like this:
通常,以上应该足够了,但是如果由于某种原因目录、文件或子目录没有所有者用户名的写权限,则可以通过更改权限以添加该写访问权限来轻松修复,如下所示:
cd /var/www/image
# recursively add "w"rite permissions for the "u"ser (owner) to current directory
chmod -R u+w .
回答by user2094324
Change edit group to www-data
将编辑组更改为 www-data
chown -R (owner):www-data (folder)
chown -R(所有者):www-data(文件夹)
And folder permission to 775
文件夹权限为 775
回答by ThebasBr
Change edit group may solve most of the problems of permissions.
更改编辑组可以解决大部分权限问题。
Changing do www-data and set permission to 775.
更改 do www-data 并将权限设置为 775。