Django development on Virtualbox: step by step setup

I had a bad morning trying to repair my Cygwin installation from a virtualenv mess. It’s time to get a Debian and install it on a Virtualbox for my new django project!

  • Windows: host
  • Debian: guest

Choosing the distro: what I want

  • Python 2.6
  • Django 1.4
  • Apache + Mysql

I’m a Debian fan from years so I go to the Debian website and download Wheezy netinst iso (32 bit, since I’m on a 32 bit OS and I want to use more core): wheezy met all the requirements above.

I already have a Virtualbox, so what I do is to add a new virtual disk and to add the new Wheezy netinst iso on CD/DVD images. Then I create a new Debian machine (32 bit) with two cores. I choose the iso image to be mounted on startup so the Debian setup process will start on boot.

As network device, I choose the Bridge option, so I can access the machine later from my windows host.

Installing the system

When you turn your machine on, many choices will be prompted to you. I install the webserver (apache) from the list, removed SQL server and print server and then leave desktop selected and the other default values. After some minutes Debian is installed and I can log in with the credential I have specified during installation.

Use WORKGROUP as network name if you’re running a Windows host when asked.

Install django packages

Under the Application menu, find the Debian package management tools to install what you want. As the requirements I’ve listeded above I search and install those packages:

  • python-django (1.4.1-2)
  • libapache2-mod-uwsgi
  • libapache2-mod-wsgi
  • mysql-server
  • samba

Later you can install more useful packages like virtualenv and phpmyadmin.

After you’ve installed those packages, you can do some test. Open a shell (Accessories > Terminal) and then type these commands:

What version of python I’m running?

$ python

Python 2.7.3rc2 (default, Apr 22 2012, 22:35:38)
[GCC 4.6.3] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

So I’ve python 2.7. Good!

>>> import django
>>> django.VERSION
(1, 4, 1, ‘final’, 0)

And I’ve Django 1.4.1.

Share your code to the Windows network (workgroup)

Now I want to read the code from one machine to another. I choose Samba server to read and write files from the virtual machine to windows and back. It will be useful since I’ve a complete Eclipse + pydev IDE on windows and I love work with it.

I open a Root terminal and type:

# ifconfig

If you choosed the Bridge network interface on installation, you will got something like this:

eth0 Link encap:Ethernet HWaddr ??????
inet addr: Bcast: Mask:
inet6 addr: ???????????/64 Scope:Link
RX packets:49280 errors:0 dropped:0 overruns:0 frame:0
TX packets:19777 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:45400047 (43.2 MiB) TX bytes:1887849 (1.8 MiB)
Interrupt:19 Base address:0xd020

The address in bold ( is the local network address of my virtual machine. If I just type this address in the Chrome browser it’s running on Windows (host) I got the “It works!” from Apache on the virtual machine. If you can’t see nothing, left click on the network icon on the bottom of your virtualbox windows > click on the menu voice and then choose the Bridge option. Then redo the ifconfig as above.

Samba tuning

Create a directory to store your django code (inside current user home folder). Open the terminal as normal user:

$ cd
$ mkdir my-django-code

Then share this folder with samba. To do this, let’s create a new user without a password:

adduser guest –home=/home/public –shell=/bin/false –disabled-password

Then add these lines to /etc/samba/smb.conf on “## Authentication ##” section:

security = share
guest_account = guest
invalid_users = root

obey pam restrictions = yes

And then after the [cdrom] commented text:

read only = no
locking = no
path = /home/myuser/my-django-code
guest ok = yes
force user = myuser

Where myuser is my (normal) user name. The lines above tell something like this to samba:

  • Let a guest user access without a password
  • …to the path /home/myuser/my-django-code
  • …”masquerading” like myuser

The “masquerade” thing is all about having the right to write files created from myuser from the guest user on the host.

When i browse my Workgroup on windows, I found the machine name I choose during installation and inside I found the my-django-code directory. I try to read and write files from the host (Windows) and from the guest (Debian) and it’s all ok.

Django, finally!

If you’re starting to develop on django, so this howto for beginners will help you a lot. Since I’ve installed the python-django package from Debian, to start a project is simple as typing this:

$ cd
$ cd my-django-code
$ django-admin startproject django_unchained
$ cd django_unchained
$ python runserver

Where is the virtual machine local network address from above and 8000 the port of the django testing webserver.

I type:

on Chrome (host: Windows) and I get the hello page from Django. Perfect!

Then, I can just follow the django howto to do the right things during the creation of my new app django_unchained!

You can also explore the must-have list of tools and sites for Python developers.

Howto merge two torrent files

Update 2017: The only working method is now to use Vuze’s Swarm Merging starting the two torrents at the same time. Vuze will auto-detect the uncompleted torrent files merging the two toghether. Remove .part extension of existing files if you put uncompleted files from another client.

Update October, 2010: before trying this howto, I suggest to try mergetorrent. It’s free software, released under GNU GPL by Eyal (read comments) and it’s simpler than the method described below. Thank you Eyal!

Sometimes you want to download a torrent that you’ve partially downloaded. Many bittorrent client allow partially downloaded files, but what if you’ve downloaded the same torrent twice, with differents parts available?

Use Zeroconf / Local peer

I’ve used two client on the same LAN, ktorrent (on Debian) and utorrent (on Windows XP). I’ve two downloaded files (or folder) from the same .torrent, with different parts downloaded.

  • Enable Zeroconf plugin on ktorrent
  • Check if on utorrent “Enable local peer discovery” is enabled
  • Import existing download #1 on ktorrent
  • On debian system, as root type ifconfig to discover your local IP address, i.e.  inet addr:192.168.0.XX
  • Go to ktorrent preferences and check the used port (e.g. 12345)
  • On utorrent go to Peers tab on #2 download. Right-click > Add peer
  • Type your first machine IP address (e.g. Debian) and the first bittorrent client port (e.g. 12345 on ktorrent),  e.g. 192.168.0.XX:12345 with no protocol prepended.

On both client you’ll notice a new peer, downloading and uploading very fast. Little after, the two downloaded files / folder could be completely merged.

You can now close #2 and continue to download the torrent on a single machine / client from external peers.

Note: I’ve tested this method on the same machine using Virtualbox (Debian as host, XP as guest).

See also:

Howto Share VirtualBox folders

Host: Debian GNU/Linux
Guest: Windows XP

Read the user manual on Folder sharing section.

  1. Install Guest Additions (Devices > Install Guest Additions)
  2. Click on folder icon on the bottom of the VirtualBox
  3. Create a new shared folder: select a directory on Host and choose a name (e.g. my_shared_folder)
  4. On a command shell (cmd) type this command
    net use x: \\vboxsrv\my_shared_folder

Where x: is a free device letter.

VirtualBox OSE Debian install howto

Tested under:

  • GNU/Linux distro: Debian lenny/sid
  • Kernel: 2.6 (2.6.22-3-k7)
  • Architecture: AMD K7 (Athlon XP 1900+)

Prerequisites: make sure you’ve selected both lenny and sid repositories. In your /etc/apt/sources.list you must read something like this:

## Debian Unstable (sid)
deb sid main contrib non-free
deb-src sid main contrib non-free
## Debian Testing (lenny)
deb lenny main contrib non-free
deb-src lenny main contrib non-free

You can also add the Virtual Box repository:

deb etch non-free
deb lenny non-free

But achtung! It’s the Evil Proprietary Version. 😉

In this howto, I install the VirtualBox OSE (Open Source Editon) available in Debian repositories.

  1. # apt-get update (necessary if you changed /etc/apt/sources.list)
  2. # apt-get install virtualbox-ose virtualbox-ose-source virtualbox-ose-modules-2.6-k7 virtualbox-ose-guest-utils virtualbox-ose-guest-source Note: virtualbox Guest Additions should be installed only if you’re running a linux distro within a virtualbox (such a virtual machine is called “guest”)Change virtualbox-ose-modules-2.6-XXX with your architecture (486,686 ecc.). The 486 version is installed by default. This is a meta-package that download the latest version of virtualbox for 2.6 kernel on specified architecture.
  3. After installation, in order to run VirtualBox, you have to plug a kernel module named vboxdrv specific for your kernel. To do this:
    1. # apt-get install module-assistant
    2. # m-a prepare
    3. # m-a a-i virtualbox-ose If you’ve installed the binary version from, specify virtualbox instead virtualbox-ose
    4. # modprobe vboxdrv

    During module-assistant auto-install (m-a a-i) of vboxdrv module, kernel headers of the running kernel are used to create the module. Then modprobe add plug vboxdrv to the running kernel. If something going wrong in this phase, follow the on screen instruction from the module assistant. Make sure you’ve downloaded the right kernel headers (module assistant should automatically do this, i.e. installing linux-headers-2.6.22-3-k7 for linux-image-2.6.22-3-k7), elsewhere module build cannot be completed.

  4. Now you can try to run virtualbox-ose. After you’ve created and run a virtual machine, you can get a message asking you to check dmesg. Open a root shell and type dmesg | grep vbox. The error message ask you to add a kernel command line about NMI watchdog. If it’s your case, do this:
    1. # gedit /boot/grub/menu.lst
    2. Find a line like kopt=... and add, before all, the required command: nmi_watchdog=0 and save. DO NOT uncomment the line, update-grub make the dirty job for you.
    3. # update-grub
    4. Reboot
  5. Reading the dmesg, you find:
    $ dmesg | grep vbox
    vboxdrv: Trying to deactivate the NMI watchdog permanently...
    vboxdrv: Successfully done.

    This meant that NMI issue is solved.

  6. Now you can run successfully the virtual machine. Enjoy virtualization! 😉

After installation:

The vboxusers group
If you want to allow your unprivileged user to use virtualbox, do:
# sudo adduser `whoami` vboxusersAdd to vboxusers group any other user you want to use this.
Install VirtualBox Guest Additions on Guest
If you want to enable some advanced features, like mouse and screen resolution tweaks, you’ve to install VirtualBox Guest Additions in the guest virtual machine. If you run a Windows virtual machine, you can get the precompiled (.exe) installer from this dedicated Google Code projectAfter you reboot guest, VirtualBox enable the advanced functionalities, like seamless mode for mouse pointer and a wide range of resolution and colors for the emulated VM video card.
Update: Well, you can also download Guest Additions from the dropdown menu (Devices) of a running guest. You’ll get a CD image to mount on virtual machine with all the packages you’ve to install.
Note: Virtualbox guest additions on the “host” (real) machine has no effect: if during boot you get the “Not in a virtual machine” error from guest additions, it simply means that your OS run on a host machine, not in a guest one.

See also: