In this post i’ll describe my experience of deploying django project to VPS-hosting.

Steps of deploying and server setup:

  1. Creation of django project
  2. Deploy setup
  3. Server setup
  4. Deploy

Creation of django project

Assume, that project is called myproject.

First, create it on local machine. We’ll need pip and virtualenv (if not installed yet).

Create virtual environment:

virtualenv venv-myproject

Acitvate it:

# on *nix system
source venv-myproject/bin/activate

REM on windows

Next it is need to create a django project skeleton. We can just install django and use command ‘ startproject’. This will create a very basic and poor project. Many time will be needed to add common used things, settings. Very useful to have your own template of a project with common used settings. I like cookiecutter, it is easy to use. You can take this template and modify it. Here is my:

Install cookiecutter:

pip install cookiecutter

Create django project from template (my template for example):


After this you’ll see question in console (project name, etc.). Initial project creation is done.

Then we work with project locally.

At some moment we are ready to deploy it. But currently our server has just OS installed and nothing else. Lets fix that (i’ll describe server with ubuntu).

Deploy setup

I deside to talk about deploy now, because it will affect all other actions.

Once i was working with project, that used makesite utility for deploy. I like it and use it with some of my projects.


makesite can install, update, unistall project on server.

At project creation makesite create all nessesary environment automatically, based on specific templates. Environment includes: creation of virtualenv, nginx configuration, uwsgi, supervisor, database initialization. So all the project needs to be started. Project install command:

makesite install <project_name>

When we need to deploy a project, we push it to remote repository (that is hosted on github, bitbucket or any other server). Then, we access our server by ssh (were project is launched) and enter such command:

makesite update <project_name>

Thats all, the project is updated.

makesite configuration

  1. Create makesite.ini. Lets call it “main”, as we’ll have another one.

     # production mode
     # project domain, will be used in nginx config
     # postgres superuser (for database creation)
     # postgres superuser password
     # database name
     # postgres user, that will have access to database (same, as in django
     # postgres user password
     # postgres host name
     # remote repository address
     # user, the makesite will work from
  2. Create in root folder of project file makesite.ini, we’ll call it “additional”:


where <project_name.settings> is path to settings module, relative to ‘’. It is needed to use ., not /.

Default settings for uwsgi, nginx and supervisor will be taken from

If you need to customize them, add following lines to “additional” makesite.ini


Create path ‘deploy/makesite_templates’ in your project, copy uwsgi dir from Then modify needed configs here ‘deploy/makesite_templates/uwsgi/deploy/’

In summary we hanve:

  • main makesite.ini (we’ll need it later on server)
  • additional makesite.ini, that is placed in project root
  • path deploy/makesite_templates/uwsgi if required.

Don’t forget to put all this stuff (except main makesite.ini) under git and push the changes..

Server setup

All commands are checked for Ubuntu 12.04.

Access server with root account.

Check python version:

python -V

I assert, that it is 2.7

# We are root
# Update the system
apt-get update
apt-get upgrade

# Compilation utils
apt-get install build-essential
apt-get install libpq-dev

# Config locale
locale-gen ru_RU.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

# git setup
apt-get install git

# setup-tools
apt-get install python-setuptools python-pip

# Another compilation packages
apt-get install python2.7-dev
apt-get install python-dev

# postgres setup
apt-get install postgresql

# modify /etc/postgresql/{postgres_version}/main/pg_hba.conf
# line
# "local   all             postgres                                peer"
# change to
# "local   all             postgres                                md5"

sudo -u postgres psql template1
#postgres superuser password
\password postgres
# !!! enter password and remember it
# press ctrl+d to exit

# postgres utils
apt-get install pgagent
apt-get install pgadmin3

#If you need to customize postgres settings, modify this file:
# /etc/postgresql/{postgres_version}/main/postgresql.conf
# Restart postgres
/etc/init.d/postgresql restart

# uwsgi
pip install uwsgi

# nginx, virtualenv, supervisor
easy_install elementtree
apt-get install python-virtualenv nginx supervisor

# working with images
apt-get install libjpeg-dev
pip install -I Pillow

# Create ssh key, that will be used by makesite
test -d .ssh || mkdir .ssh
cd ~/.ssh
#"Enter file in which to save the key": makesite
# Other question just hit enter:

  Generating public/private rsa key pair.
  Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): makesite
  Enter passphrase (empty for no passphrase):
  Enter same passphrase again:
  Your identification has been saved in makesite.
  Your public key has been saved in

# Copy to id_rsa
cp makesite id_rsa

# ! Important
# Tak public key and add it to your remote repository.
# Description from github:

# Create path, where project will be placed
mkdir /var/www

# Put "main" makesite.ini into /var/www

# makesite setup
pip install makesite

# Check bash settings
makesite shell -p /var/www
# Write them into ~/.bashrc
cat >> ~/.bashrc
# copy and paste previous output
# it was something like:

# Makesite integration
# ====================
export MAKESITE_HOME=/var/www
source /usr/local/lib/python2.7/dist-packages/makesite/

# enter
# ctrl+d to exit
# load settings for current session
source ~/.bashrc

# it is useful
apt-get install mercurial

# Now install project. It takes some time.
makesite install <project_name>

# If you see message
# at the end, then installation is done successfully.

# Check, that dependencies are installed from requirements.txt:
cd /var/www/{project_name}/master
source .virtualenv/bin/activate
pip freeze

# Check, that database is create, tables are synced, migration are applied.

# Check, that STATIC_ROOT and MEDIA_ROOT have right values.
# corresponding folders must be placed here:
# /var/www/{project_name}/master/
# if some folders are missed, you can create in manuall
# but change owner and group to www-data

# update static
# (virtualenv must be activated)
cd /var/www/{project_name}/master/source 
python collectstatic --noinput

# Restart nginx
/etc/init.d/nginx restart

Thats all, project is launched.


As it written before, to update a project make:

  • push to remote repo
  • access server by ssh and from server type makesite update <project_name>