Django uploading file - permission denied - django

I've tried everything that i've found regarding this problem, but nothing helped me to solve this issue.
When i try to upload something on my web site i get this error:
OSError: [Errno 13] Permission denied: '/home/****/www/site.com/media/news/some_file.pdf'
ls -l media gives me next:
drwxrwxr-x 2 www-data www-data 4096 Oct 11 23:13 news
so permissions are OK.
Everything was working well with development server but now in production i just cant upload anything.
How to fix this?

As a noob for linux/apache I didn't know that default user for apache in CentOS (that i'm running on my server) is apache and not www-data.
So chown -R apache:apache media did the trick.
In last few days i've searched a bunch of topics regarding this problem and none of them did mention that there's other default user but www-data. It looks like that most of users are runing Ubuntu as everyone is talking about www-data.

Related

I have Deployed My Django App in apache server . All the static files are getting served properly but its not accepting media files from Form Input

While Submitting a form having media input its showing
[Errno 13] Permission denied: '/home/ubuntu/django/media/pictures'
I have searched in google but no one told giving permissions for media files , they ever all telling about static files only . Can any one please tell me which permission i have to give to it with chmod no.
You're having permissions issues. To fix it, you need to allow the Apache process access to the folder and it's content.
This can be done through the following steps
Change the permissions to read and write
chmod 664 /home/ubuntu/django/media/pictures -R
Give the group Apache runs under (www-data group) group ownership of the folder and its content
sudo chown -R :www-data ~/home/ubuntu/django/media/pictures
Restart the Apache service
sudo service apache2 restart
If you want to ensure Django behaves as it should, you can also add the following to your settings.py
FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o755
FILE_UPLOAD_PERMISSIONS = 0o644

Cannot write in logs folder even after correct permissions

I am getting the error The stream or file "/opt/lampp/htdocs/project/storage/logs/laravel-date.log" could not be opened: failed to open stream: Permission denied
I have tried setting the permissions as both 777 and 775. I suddenly started getting this error. Here's the ls -l output of the project.
drwxrwxr-x 15 root www-data 4096 Dec 2 2018 project
I am using XAMPP for my current development environment and not the native LAMPP stack.
Okay, so I read through a comment in here and changed my directory permissions to 777 for app and public folders. 775 for storage and the rest is 664. And it worked.

Permission denied for image upload on Django rest wsgi with apache2

Main problem
When user uploads image to the rest admin portal, permission error is thrown. The backend model is a simple one with only ImageField and TextField.
My setup
Ubuntu 16.04 LTS
Python 3.6
Apache2 with mod_wgsi compiled for python3.6
The upload destination is owned by my account and wwwdatagroup(I created this group for www-data and grant 760 on the upload destination)
Here is the output of ls -l This folder is under my home directory, the image is uploaded to a subfolder of media folder.
drwxrw---- 3 MYUSERNAME wwwdatagroup 4096 Jul 30 17:48 media
This was set by chmod -R 760 media I suppose this will set the permission recursively.
Question
My wsgi process has no specific user set, so it should run under the user which apache is running on. In my case www-data. As shown above, obviously this folder and all is subfolders can be read, written(rw) by wwwdatagroup which contains www-data. So WHY PERMISSION DENIED?
Help...
I am staring at the error page and crying. Real tears.
I solved this problem by setting 770 for wwwdatagroup on the media folder. My guess is that Django is doing some listing(require x permission) or trying to mkdir(this requires x too? I don't know).
I will keep this question open and will give the accepted answer to person who explains this well. Thanks!

gcloud components update permission denied

All of a sudden I started getting "Permission Denied" issues when trying to run any gcloud commands such as gcloud components update -- the issue was avoided if I ran sudo gcloud components update but it's not clear to my why the sudo command is suddenly required? I have actually been trying to run a GCMLE experiment and it had the same error/warning, so I tried updating components and still ran into this issue. I have been travelling for a couple days and did not make any changes since these same commands worked a few days ago. Further, I did not changed my OS (Mac High Sierra 10.13.3) -- were there any changes on the Google side that might explain this change in behavior? What is the best course of action to permanently get around this warning?
(conda-env) MacBook-Pro:user$ gcloud components update
WARNING: Could not setup log file in /Users/$USERNAME/.config/gcloud/logs, (IOError: [Errno 13] Permission denied: u'/Users/$USERNAME/.config/gcloud/logs/2018.03.10/XX.XX.XX.XXXXXX.log')
after sudo gcloud components update I was able to kick off a GCMLE experiment, but I also get the same warning (though my job now submits successfully).
WARNING: Could not setup log file in /Users/#USERNAME/.config/gcloud/logs, (IOError: [Errno 13] Permission denied: u'/Users/$USERNAME/.config/gcloud/logs/2018.03.10/XX.XX.XX.XXXXXX.log')
Based on an answer to a similar question, you probably need to change the permissions to the appropriate directories:
sudo chown -R $USER ~/.config/gcloud
That same post suggests that permissions may have gotten out-of-whack by running a gcloud command with sudo.
In most cases, the problem is not caused by the ~/.config/gcloud directory but the installation directory of gcloud which is owned by root:
drwxr-xr-x 20 root staff 640 Jun 20 18:22 google-cloud-sdk
Solution:
You must change permissions for that directory to your user from:
by:
sudo chown -R $USER /Users/$USER/bin/google-cloud-sdk

django - Permission denied in uploading photos

When I try to upload an Image, I am getting an error:
OSError at /
[Errno 13] Permission denied: '/home/ubuntu/project/django-user-activities/django_user_activities/static/media/uploaded_files/1422722471_11_Tulips.jpg'
I think its related with user permission. But since I am a windows user, and I am hosting this in a ubuntu 14.04 OS, I have no idea how to solve this. How do I resolve this problem/error? I would be very much grateful if you could help me. Thank you.
The shotgun command for all permission problems:
sudo chmod -R 777 /home/ubuntu/project/django-user-activities/django_user_activities/static/media/
Please note though that this is almost never a good idea...
Read this if you want to do it properly: https://superuser.com/questions/19318/how-can-i-give-write-access-of-a-folder-to-all-users-in-linux