简体   繁体   中英

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 . 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 ps aux | grep apache or ps aux | grep httpd 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 .
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

Change edit group to www-data

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

And folder permission to 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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