Simplified Django deploy using Apache HTTP Server. We will use Vagrant and VirtualBox to test the deploy on a virtual machine.
$ git clone [email protected]:/e432f6c399adf780f6f3.git ~/django-deploy
$ cd ~/django-deploy
$ vagrant up
The source for this very minimal Django site comes from this Gist. The site is essentially the smallest, production-ready Django site (that actually does something) possible. A more detailed explanation of the code is in the README for the Gist, this deployment exercise assumes that you already have a working knowledge of Django. All that really needs to be understood for deployment is that the web server will need access to the WSGI application object. Django exposes a WSGI application object easily using django.core.wsgi.get_wsgi_application.
The Vagrantfile isn't very complex if you're at all familiar with Vagrant or just the concept of provisioning. We start with the base box (hashicorp/precise64), forward port 80 for HTTP requests, and designate a file for provisioning (bootstrap.sh).
This shell script is run by Vagrant when the VM is created. Essentially the goals of the script are as follows:
- Install needed software
- Setup a Virtual Environment
- Build the Django site from the source Gist
- Configure an Apache VirtualHost to serve the Django site