You are hereSettings up Mod_wsgi for Django on Webfaction
Settings up Mod_wsgi for Django on Webfaction
Recently, I've changed the way I deploy django application. From mod_python to mod_wsgi. I switch to mod_wsgi because of its simplicity, memory usage is smaller, setup is easy.
On Webfaction, mod_wsgi is fully supported. It is the one in the application list. Below are steps to get Django mod_wsgi up and running.
- Login to your webfaction account on the web panel.
- At Domain/Websites select Applications.
- Create your mod_wsgi application by clicking at application creation, here.
- At the application name, fill in your application name. This name will be use to create directory for your mod_wsgi application. At the selector, choose the django version you want to use. I always select Django trunk/ mod_wsgi 2.0/ Python 2.5. You can use any of django version you want but stay with the latest code is more prefer because there are a lot of new feature and bug fixing for the latest version.
- When you satisfy with your django version, click "Create".
- Webfaction will automatically setup mod_wsgi for you. The setup is include install mod_wsgi for apache, create directory and sample porject. Below are sample files created by webfaction.
drwxr-xr-x 6 meledictas meledictas 4096 Apr 19 16:12 apache2 drwxr-xr-x 3 meledictas meledictas 4096 Oct 5 06:41 bin drwxr-xr-x 3 meledictas meledictas 4096 Oct 5 06:41 lib drwxr-xr-x 2 meledictas meledictas 4096 Oct 5 06:41 myproject -rw-r--r-- 1 meledictas meledictas 264 Oct 5 06:41 myproject.wsgi
- Go to apache2/conf, you will see example conf file ready for you. All you have to you is fill in your domain name, for example,
ServerName feedfrog.net ServerAlias www.feedfrog.net WSGIScriptAlias / /home/meledictas/webapps/modwsgi/myproject.wsgi
- After finish editing conf file, go back to apache2/bin. Type ./start and visit your website!
Some tips
For my own application, I change following,
Webfaction create wsgi script for you, below is the file myproject.wsgi
import os import sys sys.path = ['/home/meledictas/webapps/modwsgi', '/home/meledictas/webapps/modwsgi/lib/python2.5'] + sys.path from django.core.handlers.wsgi import WSGIHandler os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' application = WSGIHandler()
This work fine but I want this file to be included in my project and I have some python path to be added before starting the django and I don't want to use the full path so below is my modification :P
#wsgi_handler.py import sys import os DIR = os.path.dirname(__file__) PROJECT_DIR = os.path.join(DIR, '..') sys.path.append(DIR) sys.path.append(PROJECT_DIR) os.environ['DJANGO_SETTINGS_MODULE'] = 'meledictas.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
As you can see, I load an application path as well as an inside of application path, this work great if you copy somebody and put in your project (you don't want or you can't install them as the python site-package).
You can do this task by having shell script to load the path but using python to load python path is more clear and easy, for me. This is smarter, you don't mess it installation process, let your project setup its dependencies by itself!
