/ubuntu2django

A fabric script to install django on a fresh ubuntu installation

Primary LanguagePython

Ubuntu-Django

A fabric script to automatically install and configure django, fastcgi, and nginx for either development or deployment. This script was originally based on Eric Florenzano's "Deploying a Django Site" post written as part of Django Advent for Django 1.2.

Prerequistes

  • fabric, this is a fabric script after all

      $ pip install fabric
    
  • Install ubuntu, its expected that you have installed at least Ububtu JeOS and updated your system to the latest, eg:

      $ sudo apt-get update
      $ sudo apt-get upgrade
    
  • Make sure ssh services are available to login to the ubuntu instance, eg:

      $ sudo apt-get install ssh
    
  • optionally, push your ssh key to the server

      $ fab push_ssh_cert
    

Installation (nginx, fastcgi and django)

  1. Copy the .fabricrc.sample file to .fabricrc

     $ cp .fabricrc.sample .fabricrc
    
  2. configure .fabricrc accordingly for your environment, at a minimum, you'll need to configure: django_user, django_pswd, django_site and nginx_media_root.

  3. Modify the env.hosts and env.user variables at the top of fabfile.py

  4. Execute the script

     $ fab -c ./.fabricrc install
    
  5. Now, browse to: http://yourhost.com/ and you should see "Congratulations on your first Django-powered page"

What's Next?

You now have installed django, fastcgi, and nginx with a django project installed in $HOME/django_site. You can activate your virtualenv with

    $ su - django_user
    $ source ~/virtualenvs/django_site/bin/activate
    $ cd ~/django_site

Once your in django_site you can install additional apps and/or configure the django project to your needs.

Bonus Tasks

  1. Push your public ssh keys to the server

     fab push_ssh_cert
    
  2. Terminate the service

     fab -c ./.fabricrc terminate
    
  3. Launch the service

     fab -c ./.fabricrc launch
    
  4. Restart the service

     fab -c ./.fabricrc restart
    

Problems

Some VPS providers customize their sources.list, if you receive an error like Package nginx has no installation candidate, make sure /etc/apt/sources.list has the proper sources eg:

deb http://archive.ubuntu.com/ubuntu karmic main 
deb-src http://archive.ubuntu.com/ubuntu karmic main 

deb http://archive.ubuntu.com/ubuntu karmic-updates main 
deb-src http://archive.ubuntu.com/ubuntu karmic-updates main 

deb http://archive.ubuntu.com/ubuntu karmic-security main 
deb-src http://archive.ubuntu.com/ubuntu karmic-security main 


## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu/ karmic universe
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic universe
deb http://us.archive.ubuntu.com/ubuntu/ karmic-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-updates universe

and then make sure you update apt cache:

apt-get update