0
votes

hi i try to deploy my django project 2.2v on ubuntu apache server

when i run cat /var/log/apache2/error.log i get this error:

[time] [wsgi:error] [pid 13224:tid 2323232] (13)Permission denied: [remote some number:number] mod_wsgi (pid=13323, process='django_app', application='django_project|'): Call to fopen() failed for '/root/project_name/project_name/wsgi.py'.

my wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'zettapc.settings')

application = get_wsgi_application()

This is my /etc/apache2/sites-available/django_proj.conf :

<VirtualHost *:80>
    Alias /static /root/project_name/static
    <Directory /root/project_name/static>
        Require all granted
    </Directory>

    Alias /meida /root/project_name/meida
    <Directory /root/project_name/meida>
        Require all granted
    </Directory>

    <Directory /root/project_name/zettapc>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    WSGIScriptAlias / /root/project_name/project_name/wsgi.py
    WSGIDaemonProcess django_app python-path=/root/project_name python-home=/root/project_name/venv/
    WSGIProcessGroup django_app 

</VirtualHost>

and output of on my browser is :

Internal Server Error

this the output of ps aux | egrep '(apache|httpd)' enter image description here

and output of ls -l /root/project_name/project_name/wsgi.py is:

-rwxr-x--- 1 root root 177 time /root/project_name/project_name/wsgi.py

is there something i've missed

1

1 Answers

1
votes

Most likely your wsgi file is owned by root and apache server runs as a non-root user. You can check which user your apache servers runs as with ps aux | egrep '(apache|httpd)' and which user owns your wsgi file with ls -l /root/project_name/project_name/wsgi.py

You best bet would be to move your project from the root folder to somwhere more appropriate (for example /usr/) and change it's owner using chown -r <user>:<user> <folder>

Alternatively run apache server as root but it's a really bad practice so don't do that.

edit: It might also be that your wsgi server (gunicorn/uwsgi ?) runs as the wrong user, the same fix still does the trick.