Technology
QoTD
Setup Apache/mod-wsgi/Django 1.10 on Ubuntu 16.04 LTS
Udayakumar Nalinasekaren
Apr 10, 2017
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
My Artwork
Coming soon...Latest Blog Posts
Coming Soon
Archives
Search