0

django return 500 internal server error (apache 2.4.10, ubuntu 15.04, django 1.9.6)

apache log:

[wsgi:warn] mod_wsgi: Compiled for Python/3.4.2.
[wsgi:warn] mod_wsgi: Runtime using Python/3.4.3.
[mpm_event:notice] AH00489: Apache/2.4.10 (Ubuntu) mod_wsgi/4.3.0  Python/3.4.3 configured -- resuming normal operations
[core:notice] [pid 9973:tid 140000454645632] AH00094: Command line: '/usr/sbin/apache2'
[wsgi:error] mod_wsgi (pid=9976): Target WSGI script '/home/user/KeyShare/KeyShare/wsgi.py' cannot be loaded as Python module.
[wsgi:error] mod_wsgi (pid=9976): Exception occurred processing WSGI script '/home/user/KeyShare/KeyShare/wsgi.py'.
[wsgi:error] traceback (most recent call last):
[wsgi:error] File "/home/user/KeyShare/KeyShare/wsgi.py", line 12, in  <module>
[wsgi:error] from django.core.wsgi import get_wsgi_application
[wsgi:error] ImportError: No module named 'django'

/etc/apache2/sites-available/000-default.conf file:

Alias /static /home/user/proj/Gestione/static
<Directory /home/user/proj/Gestione/static>
    Require all granted
</Directory>

<Directory /home/user/proj/proj>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
WSGIDaemonProcess proj python-path=/home/user/proj:/home/user/.local/lib/python3.4/site-p$
WSGIProcessGroup proj
WSGIScriptAlias / /home/user/proj/proj/wsgi.py

wsgy.py:

import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proj.settings")
application = get_wsgi_application()

I'm NOT using virtualenv

thanks for help

related question: HERE

EDIT: I had installed django with non-root user, now I reinstall it as root user and It works. Thanks everyone

Community
  • 1
  • 1
big
  • 73
  • 1
  • 9
  • did u install django globally using `pip install django` ? – cutteeth May 16 '16 at 13:48
  • If you think you have already installed Django, how did you install it? If you used `pip`, did you use the pip in `/home/user/.local/lib/python3.4/`? – Alasdair May 16 '16 at 13:59
  • Possible duplicate of [django apache configuration with WSGIDaemonProcess not working](http://stackoverflow.com/questions/38284814/django-apache-configuration-with-wsgidaemonprocess-not-working) – e4c5 Jul 19 '16 at 04:32

2 Answers2

0

It seems like you are missing django. This error is returned by wsgi not django. You can check using pip freeze. Make sure django is listed in the output of pip freeze. Else install django with pip using command

pip install django

It is always recommended to use virtual environment to avoid messing up with global dependencies. If working in a virtual environment does not create any problems for you, then go for virtual environment.

cutteeth
  • 2,148
  • 3
  • 25
  • 45
0

In my guess, adding path to wsgi.py may help:

import os
import sys
from django.core.wsgi import get_wsgi_application

path = '/path/to/your/project'

if path not in sys.path:
    sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()
Leonard2
  • 894
  • 8
  • 21