Django [Errno 13] Permission Denied: '/Var/Www/Media/Animals/User_Uploads'

Django [Errno 13] Permission denied: '/var/www/media/animals/user_uploads'

I have solved this myself in the end.

When running on the development machines, I am in fact running using my current user's privileges. However, when running on the deployment server, I am in fact running through wsgi, which means it's running using www-data's privileges.

www-data is neither the owner nor in the group of users that own /var/www. This means that www-data is treated as other and has the permissions set to others.

The BAD solution to this would be to do:

sudo chmod -R 777 /var/www/

This would give everyone full access to everything in /var/www/, which is a very bad idea.

Another BAD solution would be to do:

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

This would change the owner to www-data, which opens security vulnerabilities.

The GOOD solution would be:

sudo groupadd varwwwusers
sudo adduser www-data varwwwusers
sudo chgrp -R varwwwusers /var/www/
sudo chmod -R 760 /var/www/

This adds www-data to the varwwwusers group, which is then set as the group for /var/www/ and all of its subfolders. chmod will give read, write, execute permissions to the owner but the group will not be able to execute any script potentially uploaded in there if for example the webserver got hacked.

You could set it to 740 to make it more secure but then you won't be able to use Django's collectstatic functionality so stick to 760 unless you're very confident about what you're doing.

Errno - 13 Permission denied: '/media/ - Django

I got the same error and debugged it using the shell

In your settings.py file:
Change:

MEDIA_ROOT = BASE_DIR / '/media/'
# here, MEDIA_ROOT = '/media/'

To:

MEDIA_ROOT = BASE_DIR / 'media/'
# here, MEDIA_ROOT = 'path-to-project/media/'

I think this happens because you are trying to join your project level dir to the /media/ directory that exists in linux for mounting media. And would cause permission denied because root has the write permissions, you probably aren't running everything with sudo. So, instead you can remove the first \ to make the directory relative.

Django [Errno 13] Permission denied: '/var/www/media/'

sudo chmod -R 770 /var/www/ is fine.
This means that owner and group has all rights and others don't have any rights.
This is right way.
If you set 760, group users will get Permission denied on read or write attempts.

For files inside directory you can set them as 760.

Errno 13 Permission denied: media folder with localhost

When you use runserver, the process is running as your normal user; and this user has access to /home/username/ to create folders and files.

When you run it under Apache, then the code is running as the apache process - typically www-data, and that user doesn't have access to create folders under your home directory.

The solution is not to chmod 777 even though this works. There are two better ways to approach this:

  1. For production use, change the file paths to a directory where the www-data user normally has rights; and this should not be your home directory.

  2. If you must use a location under your home directory; create a new path and set its parent's owner to www-data:www-data. This will allow it to work without giving the blanket 777 permissions.

OSError at /user/1/edit [Errno 13] Permission denied: '/home/django/django_project/media/profile_pics/Square.jpg'

Change permission of /media directory.

sudo chmod a+rw  media

Errno 13 Permission denied with Django on a directory I don't want to use

In facts, Entrez.parse is calling the DataHandler objects. This objects try to write in the user directory with something like :

home = os.path.expanduser('~')
directory = os.path.join(home, '.config', 'biopython')
local_xsd_dir = os.path.join(directory, 'Bio', 'Entrez', 'XSDs')
os.makedirs(local_xsd_dir)

Because biopython user is the httpd user, the home directory is /var/www/.

The solution is here to allow apache to write into /var/www or to move it to a different place.



Related Topics



Leave a reply



Submit