0

I have a web site running on Ubuntu server with Nginx installed and I made profile picture upload in Django. However when I try to upload a new profile picture it says

[Errno 13] Permission denied: '/home/xyz/djangodir/media/profile_pics/profilepicxyz.png'

How can I allow users to write new files into the /profile_pics folder?

I am a beginner in Ubuntu and Nginx, so it might be a really easy solution.

My intuition is that it will be done using chmod or chown commands.

5
  • You need to redo whatever you did there: you -do- -not- set a webserver to a location in /home/ Make nginx point to /var/www/ and create a dir in there that you open up for "others". "My intuition is that it will be done using chmod or chown commands." sure but not in a users /home/.
    – Rinzwind
    Feb 16, 2020 at 14:14
  • @Rinzwind Any exact reason why should I put my project in /www/? I followed digitalocean guide on how to deploy django project and they did put it in /home folder - guide
    – popcorn
    Feb 16, 2020 at 17:36
  • Security. /home$USER/ is intended for the owner of that home. Nothing else. Website by default go either to /var/www/ or to a dedicated partition. Oh and please read why they say: ~/myproject/ ... that is not /home/$USER/ (a little bit less bad then what you did: their method has 1 big security issue: creating and then deleting a user called myproject can kill your website. Please keep /home for what it is intended for: to hold user and their personal data and settings)
    – Rinzwind
    Feb 16, 2020 at 18:13
  • @Rinzwind Okay, I'll switch to /www/ folder and after that will users have access to write their profile pics in the /profile_pics folder?
    – popcorn
    Feb 16, 2020 at 19:30
  • Yes. The -deepest- folder you open up for "others" with a chmod 666 (last 6 is important).
    – Rinzwind
    Feb 16, 2020 at 19:38

1 Answer 1

0

Try the following

Using /var/www/projectfiles as the webroot is a best practice.

Change the webroot owner using the below command

sudo chown -R www-data:www-data /var/www/projectfiles

and the file and folder permissions are

cd /var/www/projectfiles

and run the following commands

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;  

then give 777 permission for /profile_pics

chmod -R 777 /var/www/projectfiles/profile_pics
2
  • Could you explain me what these commands do? find . -type f -exec chmod 644 {} \; find . -type d -exec chmod 755 {} \;
    – popcorn
    Mar 26, 2020 at 12:23
  • find . -type f -exec chmod 644 {} \; find files and change permission with 644 find . -type d -exec chmod 755 {} \; find directories and change permission with 755 Note : You need to run these commands from /var/www/projectfiles/ folder
    – Vinoth Rc
    Mar 26, 2020 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .