Skip to content

Instantly share code, notes, and snippets.

@simkimsia
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save simkimsia/b127530378a7cbbae1ab to your computer and use it in GitHub Desktop.

Select an option

Save simkimsia/b127530378a7cbbae1ab to your computer and use it in GitHub Desktop.
How to develop and deploy django 1.8

develop and deploy django

First we consider the development environment.

It will be done using virtualbox + vagrant + ubuntu14.04

  1. Inside develop environment nginx (install using ubuntu repositories):
########################################
## Nginx
########################################
apt-get install \
        nginx \
        -y
 
## basic django app nginx config
read -r -d '' FILECONTENT <<'ENDFILECONTENT'
## create socket connection
## between nginx and uwsgi
## typically put the .sock
## in the webapp folder
upstream django {
    server unix:/src/uwsgi.sock;
}

## listening
server {
    listen              80 default_server;
    server_name         localhost;
    charset             utf-8;
    error_log           /var/log/nginx/django-app.log;

    location / {
        uwsgi_pass      django;
        include         /src/nginx_configuration/uwsgi_params;
    }

    location /static {
        alias /src/www/static;
    }

    location /media {
        alias /src/www/media;
    }
}


ENDFILECONTENT
echo "$FILECONTENT" > /etc/nginx/sites-available/django-app.conf
 
/etc/init.d/nginx restart
  1. install postgres (using ubuntu repositories) :
########################################
##  PostgreSQL
########################################
sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
apt-get update -y
apt-get install \
    postgresql-common \
    postgresql-9.3 \
    libpq-dev \
    -y
  1. Install python2
    apt-get install python-virtualenv -y ## for virtualenv
    apt-get install virtualenvwrapper -y ## for virtualenvwrapper
    apt-get install python-setuptools -y ## for python2.7 or above
    apt-get install python-dev -y ## ubuntu 14.04 no dev for python 2
    apt-get install links -y ##a command line web browser
    apt-get install python-flup -y ## connects python to uwsgi)
    apt-get install build-essential -y
  1. Or install python3
    apt-get install python-virtualenv -y ## for virtualenv
    apt-get install python3-setuptools -y ## for python2.7 or above
    apt-get install python3-dev -y ## ubuntu 14.04 no dev for python 3
    apt-get install links -y ##a command line web browser
    apt-get install python-flup -y ## connects python to uwsgi) 
    apt-get install build-essential -y
  1. Install supervisord
apt-get install supervisor -y

## Basic Configuration
read -r -d '' FILECONTENT <<'ENDFILECONTENT'
[program:app-uwsgi]
command = /usr/local/bin/uwsgi --ini /var/virtual/appname/uwsgi.ini

[program:nginx-app]
command = /usr/sbin/nginx

ENDFILECONTENT
echo "$FILECONTENT" > /etc/supervisor/conf.d/supervisord.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment