Webfaction Django setup use user’s apache instance running on custom port which then would be proxied by the main apache process running at the front. I try to replicate this setup on my laptop so I can easily play around with the setup without actually using webfaction server through the slow ssh connection. Webfaction use Centos while my laptop is running Ubuntu 8.04 but look’s like the setup can easily be replicate (once you get through the hardest part).

The hardest part seem to get the latest mod_wsgi (2.x) on ubuntu which still provide 1.x version through apt-get. Actually, the hardest part is to apt-get install all the apache2-devel package + dependecies through my slow Maxis broadband connection. Once you get all the packages, it just a matter of ./configure, make, make install the latest source of mod_wsgi 2.x.

The next step is to mirror up webfaction directory structure on my laptop which look like this:-

$ ls django_env apache2 bi nlib byteflow $ ls apache2 bin conf logs var

In ./apache2/bin, there’s script to start and stop the apache instance:-

!/bin/bash

export PYTHONPATH=/home/kamal/webapps/django/lib/python2.5/site-packages /home/kamal/webapps/k4ml_com_var/apache2/bin/httpd -e debug \ -f /home/kamal/webapps/k4ml_com_var/apache2/conf/httpd.conf -k start

!/usr/bin/env python

import os

stopped = False

Stop Apache if it's running.

for line in os.popen('ps -o pid,command -u kamal'): if '/home/kamal/webapps/k4ml_com_var/apache2/conf/httpd.conf' in line: stopped = True os.system('kill %s' % line.split()[0])

if not stopped: print "Apache isn't running."

and the httpd.conf file:-

ServerRoot "/home/kamal/webapps/k4ml_com_var/apache2"

LoadModule dir_module modules/mod_dir.so LoadModule env_module modules/mod_env.so

LoadModule log_config_module /usr/lib/apache2/modules/mod_log_config.so

LoadModule mime_module modules/mod_mime.so LoadModule rewrite_module modules/mod_rewrite.so

LoadModule wsgi_module modules/mod_wsgi.so

LoadModule wsgi_module modules/mod_wsgi.so

KeepAlive Off Listen 7165 LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined CustomLog logs/access_log combined ServerLimit 2

PidFile var/apache.pid WSGIRestrictStdout Off WSGIPythonPath /home/kamal/webapps/django/lib/python2.5/site-packages

NameVirtualHost 127.0.0.1:7165 ServerAdmin mail@mail.com

WSGIScriptAlias / /home/kamal/webapps/k4ml_com_var/byteflow/django.wsgi ServerName var.k4ml.com #ServerAlias www.site1com #ErrorLog "logs/site1_errors_log"

WSGIScriptAlias / /home/kamal/webapps/k4ml_com_var/myproject.wsgi ServerName etc.k4ml.com #ErrorLog "logs/site2_errors_log"

I’d also copied all the modules in /usr/lib/apache2/modules and apache2 binary to my local apache enviroment. The reason I need mod_wsgi 2.x is because 1.x doesn’t support opening Python eggs’s modules. WSGIPythonPath directive also need to be set in the httpd.conf file though the actual webfaction setup just pass it through the wrapper start script.