Enabling write permissions Ubuntu Server in var/ww

2020-05-24 17:40发布

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

5条回答
Viruses.
2楼-- · 2020-05-24 18:20

Change edit group to www-data

chown -R (owner):www-data (folder)

And folder permission to 775

查看更多
我只想做你的唯一
3楼-- · 2020-05-24 18:21

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.

ps aux | grep apache or ps aux | grep httpd should give you that answer.

Then you will usually want to make that Apache username the owner of the directory and all files and directories within it:

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 .
查看更多
够拽才男人
4楼-- · 2020-05-24 18:22

cd /var/www

sudo chmod 775 image

You'll be prompted to enter the admin password - do so, and hit [return].

查看更多
老娘就宠你
5楼-- · 2020-05-24 18:25
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.

Similarly, the following will chmod all files only (and ignore the directories):

sudo find . -type f -exec chmod 644 "{}" \;

File name with space case (thanks to Nicklas B)

find . -type f -print0 | xargs -0 chmod 644
查看更多
迷人小祖宗
6楼-- · 2020-05-24 18:31

Change edit group may solve most of the problems of permissions.

Changing do www-data and set permission to 775.

查看更多
登录 后发表回答