Subhodip1307 / Django-Deployment-Guide

In This repo there is provided full guide to Host your django site in any vps or ubuntu server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django Deployment full guide

Welcome to this repo here you will learn how to host your Django site in VPS or any Linux server. Most Django developers face problems hosting their site after creating their Django Projects so no need to worry anymore in this Guide you will learn how to host your site in any VPS on any web server. I will show here all the methods to deploy your Django project.

Project Overview

In this section we will see a quice over view that how your project should be. first look at the project files. suppose I have created project like this

  python -m django startproject myproject
              or
  django-admin startproject myproject

I have also created an app

python manage.py startapp app1

Now lets look at the Structure of our project

    myproject(the project folder name)
    |_myproject
    |_app1
        |_template
        |_static
    |_manage.py
    |_requirments.txt

In this structure You can see that I have put my tempalted and static folder in a app and your project structure should be like this. If You are unable to understand or comfuse that how use this strcutre or something like this then don't worry I will attach a sample project with this repo.

Basic VPS Configuration

In this section we will configure our VPS and donwload all dependensis for our project and we will also create a user.

Domain Pointing

If You Have a domain and want to use that doamin for your project then you need to point it towards your VPS
  • You need to add the Following records in Your Domains DNS
Record Name Host/Name IP Address
A @ Remote Server IPv4
A www Remote Server IPv4
AAAA @ Remote Server IPv6
AAAA www Remote Server IPv6

Createing a User in VPS

so in first step we need to login in our vps with ssh key or ip . Here I will use ip and username to login
ssh root@your_server_ip

example: suppose my VPS ip is :-192.168.0.1 and by default the username will be root

ssh root@192.168.0.1

And Then give your password Now we are successfully loged in our VPS, now We will create a user

adduser <username>

example:- suppose I wanna create a user name 'trisha'

adduser trisha

now we will give the user subho privilages so in our case our user is 'trisha'

usermod -aG sudo trisha

Now we will set-up our Firewall

Just run the command

ufw allow OpenSSH
ufw enable

Now all Done now exit from the vps

exit

#Uploading Django Project To our VPS

There I will discuss two methods to upload your project to your vps one is with GitHub and another one is from your Local System . We will look at both.

With Github

It's very easy to upload your project with github just relogin in vps with new username and password. ,in our case our new user name is 'trisha' and our ip is '192.168.0.1' so to login we need to run that
    ssh trisha@192.168.0.1

Now we are in our Home dirctory now just use gitclone url and clone your project

    git clone <your project github link>

And then it may ask for authentication for your github. first it will ask the github username and the password. For That situation we need to create a accesstoken from github , You can watch videos in youtube for that or I wll discuss it very soon.

Now let's see does our project successfully cloned in our VPS or not for that use this command

    ls

After that if you able to see your project name then congratulation . Now let's move on another method to upload your project

Upload From Local

We will upload the projcet from our localsystem with scp, so for that keep your project in your desktop and open terminal there (Don't forget to make it zip) now run this command.
scp -P Port_number Source_File_Path Destination_Path

example :- Nomrally we access our VPS with port 22 and our projectname is myproject.zip (I have made it zip) and Destination_Path will be our username and ip

scp -P 22 myproject.zip trisha@192.168.0.1:

Now it will take sometime and then loging in your vps with your username in our case this is 'trisha'

    ssh trisha@192.168.0.1

Now let's see does our project successfully cloned in our VPS or not for that use this command

    ls

If you see your project name then You have successfully done now let's unzip the project file inoder to do that we need to install unzip .

sudo apt install unzip

now we have downloaded unzip now let's unzip our project

unzip <your projectname>.zip

example:- In our case our folder name is myproject.zip

unzip myproject.zip

Depolyment Options

untill now we have how Can we set up our project in our vps now we gonna learn how can we depoly our project in differnt web-servers and with differnt databases.

Methods

With-Out Docker

  • Apache
  • Nginx & Uwsgi (Comming soon)
  • Nginx & gunicorn (Comming soon)

With Docker

Data Base

With-Out Docker

With Docker

  • Comming Soon ..

Django Other packages

  • Celery
  • Channels(comming soon)

About

In This repo there is provided full guide to Host your django site in any vps or ubuntu server

License:MIT License