Running a Django development environment from !VirtualBox

Please note that this recipe is not for beginners as it assumes you are already familiar installing and configuring a !VirtualBox VPS and the relevant software :)

Aim

The goal of this recipe is to run a virtual Django development machine (the guest machine). The main advantages of doing so is the possibility to emulate some workflow encountered while running and working on some Django code on a VPS. Also, this avoids you to clutter your main machine (the host machine) with dev code, Django framework, an apache server, etc...

Your Django project will be available from the host if you point your browser to http://localhost:8000, just like with a default locally installed Django dev setup.

Prerequisites

You need the following already working

Configuring Apache

On the Guest:

NameVirtualHost *:80
Listen 80
Listen 8080
<VirtualHost *:80 *:8080>


On the Host:

VBoxManage setextradata "name of the guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/HostPort" 8080
VBoxManage setextradata "name of the guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/GuestPort" 8080
VBoxManage setextradata "name of the guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/Protocol" TCP

Configuring Django

On the guest:

MEDIA_URL = 'http://locahost:8080/mydjangoapp/'
./manage.py runserver 0.0.0.0:8000

On the host:

Hints

vboxmanage list vms
VBoxManage setextradata "name of the guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
VBoxManage setextradata "name of the guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata "name of the guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
  Then, you can restart/start the guest and ssh into it with:
ssh username@localhost:2222
VBoxManage getextradata "name of the guest" enumerate