Home > Software design >  Error: (Internal server error) Django apache2 - mod_wsgi
Error: (Internal server error) Django apache2 - mod_wsgi

Time:01-03

I'm trying to deploy my django application on my remote server, but I'm getting an http 500 internal server error. Here are the configurations I made: Structure file

/home/ubuntu/project/env (virtualenv folder)
bin
include
lib

/home/ubuntu/project/
  |- manage.py
  | - env
  | - my_project

/home/ubuntu/project/my_project
    |__init__.py
    |settings.py
    |urls.py
    |wsgi.py

Fichier 000-default.conf

<VirtualHost *:80>
    WSGIDaemonProcess myproject python-home=/home/ubuntu/project/env python- 
    path=/home/ubuntu/project/my_project
    WSGIProcessGroup myproject
    WSGIScriptAlias / /home/ubuntu/project/my_project/wsgi.py

    <Directory /home/ubuntu/project/my_project>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
</VirtualHost>

Error log

  [Fri Dec 30 11:28:18.988904 2022] [wsgi:error] [pid 31289:tid 140473618372288] [remote 
  41.82.143.41:50428]   File "/home/ubuntu/project/my_project/wsgi.py", line 12, in <module>
  [Fri Dec 30 11:28:18.988915 2022] [wsgi:error] [pid 31289:tid 140473618372288] [remote 
  41.82.143.41:50428]     from django.core.wsgi import get_wsgi_application
  [Fri Dec 30 11:28:18.988933 2022] [wsgi:error] [pid 31289:tid 140473618372288] [remote 
  41.82.143.41:50428] ModuleNotFoundError: No module named 'django'
  [Fri Dec 30 11:28:19.164861 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote 
  41.82.143.41:50427] mod_wsgi (pid=31289): Failed to exec Python script file 
  '/home/ubuntu/project/my_project/wsgi.py'.
  [Fri Dec 30 11:28:19.164958 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote 
  41.82.143.41:50427] mod_wsgi (pid=31289): Exception occurred processing WSGI script 
 '/home/ubuntu/project/my_project/wsgi.py'.
 [Fri Dec 30 11:28:19.165130 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote 
 41.82.143.41:50427] Traceback (most recent call last):
 [Fri Dec 30 11:28:19.165172 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote 
 41.82.143.41:50427]   File "/home/ubuntu/project/my_project/wsgi.py", line 12, in <module>
 [Fri Dec 30 11:28:19.165183 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote 
 41.82.143.41:50427]     from django.core.wsgi import get_wsgi_application
 [Fri Dec 30 11:28:19.165212 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote 
 41.82.143.41:50427] ModuleNotFoundError: No module named 'django'

I then used this process : make custom versions of Python and mod_wsgi ourselves.

apt install apache2 apache2-dev
wget https://codeload.github.com/GrahamDumpleton/mod_wsgi/tar.gz/4.9.4
tar xvfz 4.9.4
cd mod_wsgi-4.9.4

./configure --with-python=[your python path]
## For example: ./configure --with-python=/usr/bin/python3.10

sudo make
sudo make install

## Finally:
sudo systemctl reload apache2

I use python 3.10 and apache2 and the error still persists (500 internal server error) I do not know what to do ???

CodePudding user response:

I found the answer by adding to my wsgi.py file the path where django is installed

  • Related