Installing mod_wsgi for django

Posted under » Apache » Django on 23 April 2021

After installing Apache Python mod_wsgi we have to adjust the settings if you want to run django.

Apparently by default mod-wsgi was for python2. So you have to remove it and replace it with the version for python 3.

$ sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py3

With that out of the way, now lets setup the apache.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /www/alsstudent/alsstudent

WSGIScriptAlias / /www/alsstudent/alsstudent/
WSGIDaemonProcess deyp python-path=/www/alsstudent:/www/python/student_als
WSGIProcessGroup deyp

Alias /static/ /var/www/alsstudent/static/

    <Directory /var/www/alsstudent/static/>
        Order allow,deny
        Allow from all

<Directory /www/alsstudent/alsstudent/>
Require all granted
        ErrorLog ${APACHE_LOG_DIR}/error-student.log
        CustomLog ${APACHE_LOG_DIR}/access-student.log combined

WSGI uses process and in this case, I called it deyp.

Python django path has two parts. The first is where you created the django site. 2nd is the where your python venv is.

For more info on static files.

Now edit the to the following.

import os, sys


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

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Now edit the to the following.


You have to restart your apache webserver and you will see the success page.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS