Serving Django

Running your own Apache, mod_wsgi and Django on HCOOP is reasonable easy. You must realize that you're not doing a server installation, but a local (aka your own home-directory) installation. Apache don't care, as long as you enter the correct configuration.

The only tricky part is Virtualenv. You need this popular Python tool to create a your own Django environment. Using Virtualenv is straight forward. Unfortunaly, Virtualenv makes the installation and configuration of your other tools a little bit more complex. Therefore, I created this page to help you through these steps.

1. Apache http server

Download the latest version from Choose for unix source and build your Apache yourself. If you follow the instructions, then it is quite simple. Don't forget to include the mod_rewrite module in your build. Also, don't do /apache which you're not allowed on HCOOP, but $HOME/apache. Also, notice that I use $HOME. For some reason ~/apache doesn't work with configure but $HOME works fine.

./configure --prefix=$HOME/sw/pkg/apache --enable-rewrite
make install

More information is on RunningYourOwnApache.


Just download the source, follow the instructions and you'll be fine. The documentation emphasize that use the same python version for compiling, as well as running. This is a good reason to overwrite the defaults and point to the python that you want. I want version 2.5 in a Virtualenv environment. $YOURVIRTUALENV/bin/python is a 2.5 interpreter. Notice that I will use this environment for compiling mod_wsgi, as well as running mod_wsgi with the proper instructions in httpd.conf.

./configure --with-apxs=$HOME/$YOURAPACHE/bin/apxs --with-python=$HOME/$YOURVIRTUALENV/bin/python
make install

3. httpd.conf

3.1. Server

   1 Listen 8172
   3 #not required if built-in
   4 #LoadModule rewrite_module modules/
   5 LoadModule wsgi_module modules/

3.2. Static media

You need to organize a couple of things in the Apache configuration file. First of all, you want an alias for your "favicon.ico". With a static web-site the favicon is in the document root. I prefer the favicon in the same directory as my other static media. Therefore you need an alias for the directory with your static media, as well as an alias for your favicon. Don't forget to add the Directory entry for this directory.

   1 alias /favicon.ico /$YOURPROJECT/site_media/favicon.ico
   2 alias /site_media/ /$YOURPROJECT/site_media/

For the Admin part of your Django project you will probably use the default Django admin pages and media files. Add a symbolic link to your Django directory (don't forget to add followsymlinks to your Apache configuration) and configure that one too.

   1 alias /media/ /$YOURPROJECT/media/

3.3. WSGI & Django

   1 WSGIPythonHome /afs/$YOURVIRTUALENV
   3 Alias /favicon.ico /afs/$YOURDJANGO/site_media/img/favicon.ico
   4 Alias /site_media/ /afs/$YOURDJANGO/site_media/
   6 <Directory /afs/$YOURDJANGO/site_media>
   7   Order allow,deny
   8   Allow from all
   9 </Directory>
  11 Alias /media/ /afs/$YOURDJANGO/media/
  13 <Directory /afs/$YOURDJANGO/media>
  14   Order allow,deny
  15   Allow from all
  16 </Directory>
  18 WSGIScriptAlias / /afs/$YOURDJANGO/apache/django.wsgi
  20 <Directory /afs/$YOURDJANGO/apache>
  21   Order allow,deny
  22   Allow from all
  23 </Directory>

4. AFS

On HCOOP, one should not use the normal Unix autorisation, but AFS instead. RunningYourOwnApache describes the necessary part for Apache (e.g. k5start). You must do the part of your application yourself. Notice that the autorisation is for USER.daemon instead of USER.

So far, I've found that one must set the proper autorisation for Apache itself, your virtualenv directory with Python and your Django directory. My current setup is the same autorisation for USER.daemon for all directories. Feel free to suggest a more specific setup on this page.

fsr setacl $YOURAPACHE nachtdier.daemon all
fsr setacl $YOURVIRTUALENV nachtdier.daemon all
fsr setacl $YOURDJANGO nachtdier.daemon all