Technology

QoTD

Art only begins when you are full.
மனிதன் நிறை பெற்ற பிறகுதான் அவனுக்குள் கலை ஆரம்பிக்கிறது.

Setup Apache/mod-wsgi/Django 1.10 on Ubuntu 16.04 LTS


Udayakumar Nalinasekaren
Apr 10, 2017

WSGI

Here are my findings in making Python 3.5, Django 1.10 and mod-wsgi to work with Apache2 server on an Ubuntu 16.04 LTS installation. At the time of this writing, integration does not work out of the box. I tried this setup on a Raspberry Pi running Ubuntu Mate distribution. The configuration differs from how it was done with earlier versions of Python/Django and mod-wsgi.

I installed my Python/Django environment in /home/uday/rpi-web and my Django project is named webroot. You will need to substitute your paths appropriately.

First of all, mod-wsgi that comes pre installed on the Ubuntu distribution is compiled for version 2. It needs to be upgraded. The following command removes version 2 and intalls the Python 3 compatible version.

sudo apt-get install libapache2-mod-wsgi-py3

We need to edit the apache configuration file /etc/apache2/apache2.conf next, and add the following lines at the end of that file.

WSGIScriptAlias / /home/uday/rpi-web/webroot/webroot/wsgi.py
WSGIPythonHome /home/uday/rpi-web/
WSGIPythonPath /home/uday/rpi-web/webroot/

Next we edit the default apache site configuration file /etc/apache2/sites-enabled/000-default.conf and add the following lines. If you have an already customized site configuration file, then you need to integrate the configuration properly.

WSGIDaemonProcess myapp
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
Alias /static /home/uday/rpi-web/webroot/webroot/static/
Alias /media /home/uday/rpi-web/webroot/webroot/media/

ServerAdmin uday@mymail.com
DocumentRoot /home/uday/rpi-web/webroot/

<Directory />
    Options FollowSymLinks
    AllowOverride all
    Require all granted
</Directory>

Lastly, we also need to edit the default /home/uday/rpi-web/src/webroot/wsgi.py file and make it look as below.

"""
WSGI config for webroot project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""

import os, sys, site

from django.core.wsgi import get_wsgi_application

sys.path.append('/home/uday/rpi-web/webroot')
sys.path.append('/home/uday/rpi-web/webroot/webroot')

activate_this = "/home/uday/rpi-web/bin/activate_this.py"
with open(activate_this) as f:
    code = compile(f.read(), activate_this, "exec")
    exec(code, dict(__file__=activate_this))

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webroot.settings")

application = get_wsgi_application()

activate_this.py is a file that gets installed in the bin directory when you set up your Python environment and setup Django 1.10 from your home directory as below:

createenv rpi-web
cd rpi-web source bin/activate pip3 install django==1.10

Read more on integration here


About This Site

This site is the personal website of Udayakumar Nalinasekaren. It is a pleasure to have you around. Thank you for visiting .

Terms of Use
Privacy Policy
FAQ
Sitemap

Credits

This site uses Python and Django. Uday is the developer.

Site uses Twitter Bootstrap for its responsive UI.

The free theme of this website is courtesy HTML5 Templates Dreamweaver

Get in Touch