At Bixly, we are thoughtful about cultivating a virtual environment for our clients and team-members to organize, monitor, and collaborate on...
Creating a Virtual Development Server for Django projects: Part 1
In this article, we talk about how to configure a Django development environment using VirtualBox as a development server, and your host machine as a means for writing the code. In concept, this should be doable on any VM software, but I’ll just focus on using VirtualBox. But why the …
In this article, we talk about how to configure a Django development environment using VirtualBox as a development server, and your host machine as a means for writing the code. In concept, this should be doable on any VM software, but I’ll just focus on using VirtualBox.
But why the heck would we do it? Shouldn’t virtualenv be enough? Here are some advantages and disadvantages that this kind of setup has:
- Removes all the clutter of installing tons and tons of software from your computer and into your virtual machine
- We can back up our virtual machine before trying to do something outrageous or risky
- In case we need to reformat our machine, all the installations we did for running our project can be backed up (because it’s in a virtual machine).
- The extra steps to be taken for setting up may daunt some others
- The added layer of abstraction can make some setup a little more complicated
- The VM is a command-line-only environment, we all know the feels.
We start with the easy stuff. We simply need to get the VirtualBox installer from this page: https://www.virtualbox.org/wiki/Downloads. In my case, since I am using Ubuntu, I downloaded the *.deb file. The download page should be easy to understand too. Alternatively, in Ubuntu, we can just invoke the
sudo apt-get install virtualbox
command. After installing, create a VirtualBox host-only network in the preferences of the menu bar. Note the network configurations it created (ok, usually the network it created is in 192.168.56.xxx)
Illustration 1: Creating a Host-Only Network
Creating the Guest Machine
To begin, we need to download the appropriate *.iso of choice for our guest machine. I used Ubuntu 11.10-alternate (soon to be upgraded to 12.04 – an LTS release, so that it will finally feel like a server) for the moment. I would like to say that from here on out, I might be using Ubuntu-specific commands without warning.
We need to create a guest machine for VirtualBox. We just need to click that big “New” button on the top in VirtualBox’s UI. This will take you to a wizard where most of the prompts should be self explanatory. The base memory size I allocated for my guest machine is just 160MB since it is a command-line environment and I will be the only user for now, so it should not need much RAM (plus I don’t have much RAM as well). Adjust accordingly if you wish. We’ll just create a new hard disk. Whether it is dynamically-sized or fixed, it’s up to you. I also just allocated 2.5GB for it, but again, you’re welcome to put in more, if you feel like it. 2.5G has been pretty sufficient for me. The rest should be just clicking next all the way and we shall have created our new guest machine. Go to the settings window of the guest machine and into the network part. Assign the VirtualBox host only network we just recently created as the first adapter and NAT as the second adapter. We can choose to assign the second adapter as a bridged adapter if you want to share your virtual machine to others.
Illustration 2: The New Button over there!
Illustration 3: Guest settings — network
Now, power on the machine and it will prompt you with a “First Run Wizard” thingy and will prompt you where your machine will be booting. Select the *.iso file you have downloaded and start. Remember to install a command-line only environment or the 160MB RAM will not be enough. I am not going through the installation steps as I am hoping we know this already (or there are others with far better instructions). Also, just an optional thing, I named my user with “vdev” and gave it the password “vdev”.
Configuring your Guest Machine
Now that we have installed our guest machine, there are now packages that needs some installing. These are:
- VirtualBox Guest Additions
- This is for shared folder capabilities. Since you will only be running your sites in the guest machine (like an actual server), your guest machine needs to access to the codes. You will be accessing your site in your host machine (nothing graphical to render in your guest machine, just pure textual and binary data serving)
- You cannot apt-get install this as this is not an Ubuntu package, so what we need to do is:
- Click the “Install Guest Additions” in the application menu of the guest machine VirtualBox window
- SSH Server
- You will need to install the openssh-server package for this.
- We will want access to the virtual machine in a terminal window from your host machine. But later when we’ve managed to configure the IP address for this guest machine
- We need to remove every vim-related package for now (vim-tiny and vim-common). We’ll just reinstall vim-common later when we run sudo apt-get install vim.
- Not even the guest machine preparing for Python/Django development would only make this pointless. So do sudo apt-get install python-virtualenv
This ends part 1 of the post for Creating a Virtual Development Server for Django Projects.
See Part 2 for more.