How to Deploy Django Application

Django comes with a development server that helps run django projects in locahost. However, to make your web application available worldwide you will need a host machine. Amazon Web Services (AWS) provides EC2 (Elastic Compute Cloud) which is the most popular choice to host django web-applications.

Creating EC2 instance with Ubuntu

Visit AWS Console first and login. Now follow simply steps to create EC2 instance with Ubuntu 18.04

Step 1: Select EC2 from AWS Console

EC2 instance

Step 2: Launch a new instance

Launch EC2 instance

Step 3: Select Ubuntu 18.04 server

Select Ubuntu 18

Step 4: Download pem file which will be used as password

Download pem file

Step 5: Wait for initialization to complete

Initialize EC2 instance

Step 6: Setup Security Group to accept HTTP and HTTPS inbound request

Security Groups

Deploy Django Project on AWS - EC2

Run the series of below commands after logging in to your Ubuntu instance:

                                    
    sudo apt update & sudo apt upgrade
    alias python = python3
    
    
    sudo apt install python-pip
    python -m pip install --upgrade pip
    pip install django==2.2
    
    
    python --version
    pip --version
    django-admin --version
    
    
    scp -i *.pem source_directory.zip ubuntu@public_ip:~/
    sudo apt install unzip
    unzip source_directory.zip
    
    
    sudo apt install screen
    screen
    python3 manage.py runserver 0:8000
    Ctrl + A + d
                                

Now visit, public_ip:8000 in your web browser to access your project.