Enabling write permissions Ubuntu Server in var/ww

2020-05-24 17:41发布

问题:

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

回答1:

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


回答2:

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 .


回答3:

Change edit group to www-data

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

And folder permission to 775



回答4:

cd /var/www

sudo chmod 775 image

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



回答5:

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

Changing do www-data and set permission to 775.