mysqldjangosecuritypermissionsdeploying

Django, permission error :OSError at /upload/ [Errno 13] Permission denied:


I get this error when i try to upload an image:

OSError at /upload/

[Errno 13] Permission denied: '/var/www/p/p/media/imgupload/img.png'

my virtualhost:

<VirtualHost *:80>
    ServerAdmin myemail@gmail.com
    ServerName p.com
    ServerAlias www.p.com
    DocumentRoot /var/www/p/
    LogLevel warn
    WSGIDaemonProcess processes=2 maximum-requests=500 threads=1
    WSGIProcessGroup %{GLOBAL}
    WSGIScriptAlias / /var/www/p/p/wsgi.py
    Alias /media /var/www/p/p/media/
    Alias /static /var/www/p/p/static/
</VirtualHost>

Here is the sec for the files:

drwxr-xr-x 3 ubuntu root     4096 Jun 16 13:10 www
drwxr-xr-x 4 ubuntu ubuntu 4096 Jun 16 13:10 p
(all other folders are ubuntu ubuntu)

while i got this:

drwxr-xr-x 36 ubuntu root     4096 Jun 11 06:33 lib
drwx------ 6 mysql  mysql   4096 Jun 17 14:19 mysql

I can't cd through mysql with my ubuntu user... Is it some security issue??

Must be...

Thanks in advance


Solution

  • This is a simple fix. Your django process is probably not running under the same user as the owner of the media location. Either check your config for how you have django set up through apache and make sure the owner of the media dir matches, or just open up permissions more to get it working:

    chmod -R a+w /var/www/p/p/media
    

    Or

    chown -R right-user /var/www/p/p/media