[Errno 13] Permission denied: '/var/www/mysite2/media/' after deployment.

Hi, I have hosted my website according to your website guidance. And my website is working after hosting but when I try to access my media directory, I get this [Errno 13] Permission denied: /var/www/mysite2/media/ I have Built my website using Django framework python with apache server and mysql database. Actually I have hosted two websites on a single droplet. And my first website working properly, and this is my second website which causes this type of error. So please help me.

This is my site.conf

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request’s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerAdmin webmaster@localhost
#DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

Alias /static /var/www/mysite/staticfiles
    <Directory /var/www/mysite/staticfiles>
            Require all granted
    <Directory /var/www/mysite/mysite>  
                Require all granted
WSGIDaemonProcess djangohost2 python-path=/var/www/mysite python-home=/var/www/mysite/djangohost2
WSGIProcessGroup djangohost2
WSGIScriptAlias / /var/www/mysite/mysite/

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

vim: syntax=apache ts=4 sw=4 sts=4 sr noet

And this permissions on /var/www/

drwxr-xr-x 13 root root 4096 Sep 19 13:05 mysite2
drwxr-xr-x 8 root root 4096 Sep 14 10:20 mysite1
drwxr-xr-x 2 root root 4096 Sep 14 08:58 html

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hi there @akshaykoshti401,

I would recommend starting with checking your Nginx error log:

  1. sudo tail -100 /var/log/nginx/error.log

It is possible that the Nginx user does not have read permissions for the /var/www/mysite/staticfiles folder and the files inside.

I could suggest changing the ownership of that folder and the files inside it to the Nginx user.

You can do that with the following command:

  1. chown -R www-data: /var/www/mysite/staticfiles

Note that you might have to change the www-data with your actual Nginx user in case that you changed it.

Regards, Bobby

sudo chown -R your_username:your_group /var/www/mysite2/media/

If it doesn’t work for ‘www-data’ user, try changing permission to ‘django’ user instead.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel