Deploying a Django Web App

Written by Art, June 21, 2017

Deploy Django App to Debian Linux Systems

Before Deployment

Change file

1. Make sure you switched Debug to False

2. Change ALLOWED_HOSTS to your IP address

3. Static files

STATIC_URL = '/static/'       
STATIC_ROOT = '/var/www/env/your_folder_from_github/your_project/static/'
    os.path.join(BASE_DIR, '/var/www/env/your_folder_from_github/your_project/staticfiles/')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, '/var/www/env/your_folder_from_github/your_project/media/')

Get connected

Open terminal and connect to IP address

ssh root@ip.address

Enter password from your hosting co

Install Apache2 and Python tools

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git
sudo apt-get install apache2
sudo apt-get install python-pip python-virtualenv
sudo apt-get install python-setuptools python-dev build-essential
sudo apt-get install libapache2-mod-wsgi-py3
sudo apt-get build-dep python-imaging

Start Virtualenv and install Python3

sudo pip install virtualenv
cd /var/www

mkdir env && cd env
virtualenv -p python3 .
source bin/activate

Check Python version

python --version

Clone github repo to your server

git clone

Get into your cloned directory

cd your_folder_from_github

Install all libriaries from requirements.txt

pip install -r requirements.txt

Get into your project directory

cd your_project

Create db and create a super user

python migrate
python createsuperuser

Create Static & Media Root directories.

Make sure you are in /var/www/venv/your_folder_from_github/your_project/

mkdir static
mkdir staticfiles
mkdir media

Open 000-default.conf with nano is a text editor

sudo nano /etc/apache2/sites-available/000-default.conf

Change Apache2 configuration

<VirtualHost *:80>
	ServerName localhost
	ServerAdmin webmaster@localhost

Alias /static /var/www/env/your_folder_from_github/your_project/static
<Directory /var/www/env/your_folder_from_github/your_project/static>
   Require all granted

Alias /media /var/www/env/your_folder_from_github/your_project/media
<Directory /var/www/env/your_folder_from_github/your_project/media>
   Require all granted

<Directory /var/www/env/your_folder_from_github/your_project/your_project>
        Require all granted

WSGIDaemonProcess home python-path=/var/www/env/your_folder_from_github/your_project/:/var/www/env/lib/python3.5/site-packages
WSGIProcessGroup home
WSGIScriptAlias / /var/www/env/your_folder_from_github/your_project/your_project/

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Add User Permissions

Add User Permissions (to modify sqlite3 Database). sudo chown is a command to change the ownership of a file/folder at a time to a specified user. CHOWN stands for CHange file OWNer. sudo chmod 755 filename command - you allow everyone to read and execute the file, and the file owner is allowed to write to the file as well. sudo chmod 777 means making the file readable, writable and executable by everyone.

sudo adduser $USER www-data

sudo chown www-data:www-data

sudo chown www-data:www-data

sudo chmod -R 775

sudo chmod 777

Collect static files

python collectstatic

Restart Apache server

Restart Apache server, do it everytime after changes been made to the site

service apache2 restart

Share with:

About author


Art is a FinTech enthusiast who has a great passion for coding and teaching. He earned a M.Sc. from Adelphi University, Garden City, New York. Currently, he develops software for the financial services industry and leads classes and workshops in Python at

Python for Web Scraping Online Livestream

We go through the whole process of gathering, storing and analyzing data from the Web


Python Fundamentals

Easy way to learn fundamentals of Python for complete beginners