简体   繁体   English

在var / www / image目录中启用写权限Ubuntu Server

[英]Enabling write permissions Ubuntu Server in var/www/image directory

我正在尝试让我的php测试上传脚本工作,并想知道该命令将允许文件上传到var / www / image目录中的ubuntu服务器

What username will be uploading the files? 用户名将上传哪些文件? Usually on Ubuntu the Apache web server username is www-data . 通常在Ubuntu上,Apache Web服务器用户名是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. 您可以通过在进程列表命令中查找Web服务器进程并查看运行它的用户名来确认。

ps aux | grep apache ps aux | grep apache or ps aux | grep httpd ps aux | grep apacheps aux | grep httpd ps aux | grep httpd should give you that answer. 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 .
cd /var/www/image

For file like image you don't need execution permission : 对于像image这样的文件,您不需要执行权限:

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

Change edit group to www-data 将编辑组更改为www-data

chown -R (owner):www-data (folder) chown -R(所有者):www-data(文件夹)

And folder permission to 775 和文件夹权限775

cd /var/www

sudo chmod 775 image

系统将提示您输入管理员密码 - 执行此操作,然后单击[返回]。

Change edit group may solve most of the problems of permissions. 更改编辑组可以解决大多数权限问题。

Changing do www-data and set permission to 775. 更改www-data并将权限设置为775。

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

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