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.
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.
In this section we will configure our VPS and donwload all dependensis for our project and we will also create a user.
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 |
ssh root@your_server_ip
example: suppose my VPS ip is :-192.168.0.1 and by default the username will be root
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
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.
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 thatNow 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
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 [email protected]:
Now it will take sometime and then loging in your vps with your username in our case this is 'trisha'
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
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.
- Apache
- Nginx & Uwsgi (Comming soon)
- Nginx & gunicorn (Comming soon)
-
Nginx & gunicorn (Comming soon)
- Comming Soon ..
- Celery
- Channels(comming soon)