Productivity Sync Just another WordPress weblog

June 21, 2009

Django-Postgresql in a ubuntu command line VBox setup.

Filed under: Uncategorized — admin @ 3:54 pm

Last Friday I set up a VBox running the command line (alt-CD install) of Ubuntu 9.04 such that I could do some Django development and simulated deployment in the comfort of my home system.  I’m sure I did some things wrong but it mostly works (although shared Django hosting in the VM is still not completely happy).  Anyway before I forget what I did I’m slapping it in my blog.

  • Install Ubuntu-9.04-alternate-i386.iso using vbox
  • set the vbox to mount and boot from the iso
  • hit f4 of the isolinux boot loader and selected command line install
  • do the install dance.

note: default networking is a NAT through your host network.  Its ok getting the guest to talk to the world but getting the world to talk to the guest isn’t so cool with the NAT.

  • install Django and postgres and stuff
  • apt-get install ssh vim ipython libapache2-mod-wsgi pytho-psycopg2 postgresql
  • apt-get install apache2-doc postgresql-doc-8.3 (if you want too)
  • Set up host and VBox for Bridged adapter on tap1
  • shut down the Vbox guest and hit settings/network/adapter 2 and selected bridged adapter and name it tap1
  • on host : apt-get install bridge-utils uml-utilities
  • create a scrip with the following content in it (to run from root):

root@mgross-desktop:~# cat
# set PATH for the case we are called via sudo or su root


# create a tap
tunctl -t tap1 -u mgross
ip link set up dev tap1

# create the bridge
brctl addbr br0
brctl addif br0 tap1

# set the IP address and routing
ip link set up dev br0
ip addr add dev br0
ip route add dev br0

  • run script.
  • start vbox
  • scp Django-1.0.2-final.tar.gz
  • install Django on guest (do default install)
  • Set up host for sshfs / fusefs access to the vbox gest for easy coding using host tools.
  • apt-get install sshfs
  • sudo mkdir /media/guest
  • sudo chow mgross /media/guest
  • sudo addusr mgross fuse
  • sshfs /media/guest
  • On guest Configure Apache.
  • edit /etc/apache2/sites-available and add one line per shared site from your guest:
WSGIScriptAlias /mysite /home/mgross/sites/apache/mystie.wsgi
  • add the *.wsgi file to get the Django serving…
import os
import sys
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
  • set up postgress on guest
  • sudo -u postgres psql postgres
  • sudo -u postgres createuser -P mgross
  • sudo -u postgres createdb -U mgross mysite
  • edit /etc/postgresql/8.3/main/pg_hba.conf and change the “local” config to:

local all all md5 <– was local all all ident sameuser

  • Fix ups that seem to work fine from the Django test server but fall over when running on the production.
  • set up sim links in /var/www/media so that adim pages work
cd /var/www/media/
ln -s /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/css
ln -s /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/cs
ln -s /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/js
ln -s /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/img

  • Settings file for Django tutorial mysite test site:

# Django settings for mysite project.

DEBUG = True

# (‘Your Name’, ‘’),


DATABASE_ENGINE = ‘postgresql_psycopg2’           # ‘postgresql_psycopg2’, ‘postgresql’, ‘mysql’, ‘sqlite3’ or ‘oracle’.
DATABASE_NAME = ‘mysite’             # Or path to database file if using sqlite3.
DATABASE_USER = ‘mgross’             # Not used with sqlite3.
DATABASE_PASSWORD = ‘mgross’         # Not used with sqlite3.
DATABASE_HOST = ”             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ”             # Set to empty string for default. Not used with sqlite3.

# Local time zone for this installation. Choices can be found here:
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = ‘America/Los_Angeles’

# Language code for this installation. All choices can be found here:


# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: “/home/media/”

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: “”, “”

# URL prefix for admin media — CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: “”, “/media/”.

# Make this unique, and don’t share it with anybody.
SECRET_KEY = ‘9$s*d_msxvb6dla2126u!wjb=ohkv8uk9%i02)i7%vmcn@@zbz’

# List of callables that know how to import templates from various sources.
#     ‘django.template.loaders.eggs.load_template_source’,


ROOT_URLCONF = ‘mysite.urls’

# Put strings here, like “/home/html/django_templates” or “C:/www/django/templates”.
# Always use forward slashes, even on Windows.
# Don’t forget to use absolute paths, not relative paths.


  1. tips and tricks (and some refrence URL’s I used.)
    1. cat /var/log/apache2/error.log is your friend
    2. /etc/init.d/apache2 restart will get tiersome
    3. This install isn’t perfect because it still has some warts to work out with the paths.  (reverse fails..)
    4. URLs:

Powered by WordPress