'PermissionError: [Errno 13] Permission denied:' when uploading to /media/ - django

I get this error PermissionError: [Errno 13] Permission denied: '/svr/portfolio/media/projects/2019-09-11_05-13-24.png' when I try to upload an image to /media/ from the admin panel
I tried sudo chmod -R 770 /svr but it makes my entire website unusable due to permissions.
With sudo chmod -R 755 /svr it becomes usable again

I solved this by running chown www-data:www-data -R media

Related

Django/apache NLTK Permission denied: '/var/www/nltk_data'

I'm using NLTK with my Django/Apache application, however when loading a page it returns Permission denied: '/var/www/nltk_data' error. I made my user (not root) the owner of /var/www and gave permissions with sudo chmod -R 770 /var/www/. What else can I do to remove this error?
Try sudo chmod -R o+r /var/www/ This will add read permissions to other.
The apache user trying to write to /var/www/nltk_data folder is www-data. So I made this user the owner of nltk_data folder then it worked.

Permission denied to upload folder Django

I am trying to upload images in django. I have set static directory in settings.py
MEDIA_ROOT = os.path.join(BASE_DIR, '/assets/image/')
MEDIA_URL='http://127.0.0.1:8000/assets/image/'
here is my model image Field
doImage=models.ImageField(upload_to='doImage/%Y/%m/%d',verbose_name='Do Image')
Now when i tried to upload it then i faced permission denied 13 error.
I had tried command chmod with 777 to give a permissions to folder
sudo chmod -R 777 assets
i also had tried change user of file using command
sudo chown -R hassan:hassan assets
But both things didn't worked for me. So anyone have idea that what's going wrong let me know.
Django stores files locally using MEDIA_ROOT and MEDIA_URL. Please refer this doc for more details.
For example you can also check this.
Don't do:
sudo chown -R root:root assets
This way only root user has rights over assets
Do:
sudo chown -R your_user:your_user /path/to/your/assets

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

I can not add a comment to this post - https://stackoverflow.com/a/21797786/6143954.
So I created a new question.
It was the correct answer before it was edited. In this answer, the line
sudo chmod -R 770 /var/www/
is replaced by
sudo chmod -R 760 /var/www/
Specifically, this solution is not suitable for Django.
The answer should not be changed after it has been marked as the right solution.
That was the correct answer before correcting the original post.
The GOOD solution would be:
sudo groupadd varwwwusers
sudo adduser www-data varwwwusers
sudo chgrp -R varwwwusers /var/www/
sudo chmod -R 770 /var/www/
How correct is this solution?
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.

Amazon AWS Filezilla transfer permission denied

I have my instance of the Amazon AWS running, test page is up.
I am trying to SFTP the files to the server to display my website. I have Filezilla connected to the AWS server but when I try to move the files from my local machine to the /var/www/html directory, it says permission denied.
I just figured out I CAN move the files to the /home/ec2-user directory. So my files are on the server I guess. But when I try to move them from there to the /var/www/html directory, it still won't move them, permission denied.
I've been researching this for approximately 2 hours now but I haven't been able to locate the answer to this.
Any help is greatly appreciated, i'm so close! Haha
Thanks
UPDATE
To allow user ec2-user (Amazon AWS) write access to the public web directory (/var/www/html),
enter this command via Putty or Terminal, as the root user sudo:
sudo chown -R ec2-user /var/www/html
Make sure permissions on that entire folder were correct:
sudo chmod -R 755 /var/www/html
Doc's:
Setting up amazon ec2-instances
Connect to Amazon EC2 file directory using Filezilla and SFTP (Video)
Understanding and Using File Permissions
if you are using centOs then use
sudo chown -R centos:centos /var/www/html
sudo chmod -R 755 /var/www/html
For Ubuntu
sudo chown -R ubuntu:ubuntu /var/www/html
sudo chmod -R 755 /var/www/html
For Amazon ami
sudo chown -R ec2-user:ec2-user /var/www/html
sudo chmod -R 755 /var/www/html
In my case the /var/www/html in not a directory but a symbolic link to the /var/app/current, so you should change the real directoy ie /var/app/current:
sudo chown -R ec2-user /var/app/current
sudo chmod -R 755 /var/app/current
I hope this save some of your times :)
If you're using Ubuntu then use the following:
sudo chown -R ubuntu /var/www/html
sudo chmod -R 755 /var/www/html
This work best everyone
chmod ugo+rwx your-folder
https://help.ubuntu.com/community/FilePermissions
In my case, after 30 minutes changing permissions, got into account that the XLSX file I was trying to transfer was still open in Excel.
for me below worked:
chown -R ftpusername /var/app/current

'[Errno 13] Permission denied: '/static'' even when I have permissions? Django Admin

I recently finished deploying my website using apache2 and django. I was testing everything, including the uploading process. But, when I select a file to upload and hit 'Save', it gives me an error:
PermissionError at /admin/path/path2/add/
[Errno 13] Permission denied: '/static'
I have all the right permissions, since I wrote these commands to allow permissions:
sudo chown -R :www-data project/static
sudo chmod -R 775 project/static
sudo chown :www-data project/db.sqlite3
sudo chmod 664 project/db.sqlite3
sudo chown :www-data project/
This works, since when I do ls -l, the permissions are correct.
This is my apache2 config file (just the static folder part):
Alias /static /home/alexholst/excelsite/static
<Directory /home/alexholst/excelsite/static>
Require all granted
</Directory>
My settings.py file has this as STATIC_ROOT and STATIC_URL:
STATIC_URL = '/static/'
STATIC_ROOT = '/home/user/project/static'
I dont know if this has to do with anything, but my css does load so i dont think it should have to do with the settings.py.
Any suggestions are very much appreciated!