Creating a Virtual Development Server for Django projects: Part 2

This is the second part of our tutorial, check out Part 1 if you haven’t already!

If you, the reader, have some server admin-fu and have come to realize that you already know what you are doing, then feel free to either skip this part or consider the end of the post in the previous section. I, the author of said post, do not have any administration-fu and might be saying something professionally wrong here. Feel free to comment on my shortcomings.

Scripts and Arrangement of Files

Your home directory will be empty; I that recommend you create the “bin”, “sites”, and “envs” directories here.

    • This folder will be automatically appended to the PATH by Ubuntu. It is so that you can call executable scripts as though you just installed them by apt-get install.
    • Of course, this will not take effect until your next restart with the VM
    • This is where we will put all our shared folders
    • We just have to make sure that when mounting shared folders, the permissions of the mounted shared folder and its files are given to the current user
    • This is where we will put all our per-project virtualenvs.
    • We have to put the virtualenvs inside the guest machine (obviously, right?) because that’s where we’ll be running Django’s development server. Sadly, we cannot put the env inside the project folder. Some errors about permissions happens when we create the virtualenv.

My Scripts and Stuff

Apparently, I am also the lazy type to do the same things repeatedly so I created 3 basic bash scripts. 2 independent scripts in case I need to call them independently and 1 script to call both (which is only used on startup). I am giving myself the liberty of posting here the scripts, in case you might want to copy them.

The startup script (filename: init-server):

The script for initializing the network interfaces (filename: Inuit-network):

The script for remounting the shared folders (filename: init-vboxsfs):

 

Workflow

I will be skipping the part where we mount the shared folders and create a virtualenv. Also, I would also like to assume that Django is already installed and your guest host-only network IP is 192.168.56.2.

  • Edit your host machine’s /etc/hosts file. Add the ip 192.168.56.2 entry with a custom domain name of your own. This can also be used for logging into your guest machine via SSH. There can be as many 192.168.56.2 entries as you want. For now, let’s assume that your host entry is:
    192.168.56.2 default.test-server.com
  • SSH into your guest machine
  • activate your project’s virtualenv
  • go to your project’s mounted directory and run: ./manage.py runserver 192.168.56.2:8000
  • On your host machine, open your browser and go to: http://default.test-server.com:8000
  • Voila!
  • This ends the post. I hope that you, the readers, found this useful.