/setup-django-web-server

Setup Django with virtual environment on Nginx and Gunicorn or Apache and mod_wsgi with PostgreSQL or SQLite.

MIT LicenseMIT

Setup Django on Web Server

Install and setup Django with PostgreSQL or SQLite, Nginx with Gunicorn or Apache with wsgi on virtual environment.

Essential Setup / Requirement

Setup

  • Setup Region and Local Zone on OS
  • sudo apt install python3-pip python3-dev python3-venv
  • sudo apt install curl git sqlite3 build-essential

Firewall (optional)

  • sudo ufw allow 8000
  • sudo ufw delete allow 8000
  • sudo ufw allow 'Nginx Full'

Workspace

  • mkdir ~/dummyapp
  • cd ~/dummyapp

Virtual Environment

  • sudo -H pip3 install --upgrade pip
  • sudo -H pip3 install virtualenv
  • virtualenv venv
  • source venv/bin/activate

HowTo: Nginx - Gunicorn (EN - IT)

For install Django on Nginx with Gunicorn (english howto - italian howto) for multiple site and specific virtual environment view folder nginx-gunicorn

HowTo: Apache - mod_wsgi (EN - IT)

For install Django on Apache with WSGI (english howto - italian howto) for multiple site and specific virtual environment view folder apache-wsgi

PostgreSQL

  • sudo apt install libpq-dev postgresql postgresql-contrib
  • verify
    • client_encoding TO 'UTF-8'
    • timezone TO 'UTC or YOUR TIMEZONE'
    • default_transaction_isolation TO 'read committed'
  • sudo systemctl status postgresql
  • sudo systemctl start postgresql or sudo pg_ctlcluster 12 main start
  • sudo systemctl enable postgresql
  • sudo -u postgres psql
CREATE DATABASE dummydb;
CREATE USER dummyuser WITH PASSWORD 'dummypassword';
GRANT ALL PRIVILEGES ON DATABASE dummydb TO dummyuser;
  • \q