Deploy Django Project on AWS EC2 Instance | Ubuntu Server | Nginx | Gunicorn

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to my YouTube channel in this video we are going to discuss how we can deploy a Django application on AWS so let's start with our agenda we need to follow these all points to deploy our Django application on AWS first of all we will create our AWS ec2 instance then we will clone a git wrapper and then we will connect with ec2 instance using SSH and then we will set up johnnycon and nginx and then we will load static files and start Services then we will test our application in browser okay so let's jump into Point number one so we can discuss how we can create an ec2 instance if you have AWS account you can just go to ec2 dashboard and you can create AWS Institute instance if you don't have you can create AWS account first okay then we will set up some security groups and then we will connect with our instance using SSH via local terminal okay so let's start with our Ubuntu ec2 instance creation okay I'm on my AWS dashboard so I will go to my ec2 dashboard you can also search from the Top If You Don't found how to go to ec2 dashboard you simply just type ec2 and you will be on the ec2 dashboard so I will launch a new instance first of all I have to give the name to my ec2 instance so I am given to the name demo ec2 app okay so I have given a name I will you know select the machine so there are multiple machines available so we can choose so I'm going need to use Ubuntu machine then we have to select our instance type so you can choose your instance type as your requirement so I'm going with my default configuration I will choose this T2 micro because this is a demo video so next I will create a key pair we will use this keeper to connect with our ec2 instance via local terminal then we have to select our security groups I have to just allow the traffic for HTTP and https this is very important you have to only allow your IP for SSH for the security concerns okay then we can change the storage and other details but by default we can leave it I will click on launch instance foreign I will go to the dashboard rpc2 this is our instance so it will be ready in next one minute okay our instance is running so now we will connect with our instance using SSH commands so I will go to connect we will use this command and this to connect with our terminal so I will just copy this and well I will go to my terminal make sure you are in the same directory where your M file is downloaded so I will run fast command and then I will copy the next command foreign further so we can process how we can now deploy our application on AWS before installing johnny-con and nginx we have to update our machine and we need to clone our project okay we will follow this article throughout our video for commands so we will follow this as well so you have to follow the video and article board together so you can copy some commands some Scripts so first of all I will just copy these first two commands so we can update our machine and install python pip and nginx at once so thank you okay when the installation will be completed we have to move to the next step which is to install the virtual environment on our Ubuntu machine so I will copy these two commands together so I will when this execution will be completed so we will paste these two commands so virtual environment will be installed okay I have just pasted the next two commands so we can install virtual environment okay we are done with our virtual environment now next we have to clone our git trap on so if you have your own git wrapper you can clone it otherwise I will show you my git repo we are using in this video so let me go to my GitHub okay I will clone this my GitHub wrapper you can also clone if you want this is public okay our git wrapper is cloned so I will just check it you can run command LS and you will see you have the project ready so I will just open this project okay so we have to follow next next we have to okay so we know we need to create a virtual environment before we move so first of all I will create virtual environment then I have to activate this spiritual environment and after that I will install all the packages available in my requirement.txt files okay virtual environment is activated all the packages in my requirement.txt file will be installed okay so we are done with our packages installation foreign and nginx on our ec2 instance so actually johnnycon is a pure python HTTP server for web server Gateway interface applications so we will it will communicate with our Django application and it will pass the response to nginx so we will use nginx because it will be a web server it will also serve our static files okay so let's install and configure both things on AWS instance okay we need to copy this so we can install Johnny core and then we have to run some migration command and collect status so I will just run these three commands together some of our packages is not installed let me go one by one okay this package is not installed so first of all I will install this package you need to just paste if if somehow if any package issue comes out you can just simply install it so I will just first of all install this oh sorry I need to copy this okay it's copied so I can just install this package okay now I will run my migrations okay it's run successfully so I can run my previous commands easily migrate okay all the tables are you know ready to use no I will run blood static this is my yeah this command okay so we are done with our migrations and collect static files okay so let's move to the Journey go on setup so first of all we need to create this file and we will paste the content there foreign I have to just copy the same content and we need to save the file then okay I will press escape and I will just save it okay then I have to copy the next command we need to copy this okay okay we need to know copy the content of this file and paste here okay this content we need to copy so here I want to tell you make sure your project folder name is correct okay this thing and this is also your project folder name make sure and this is your setting dot Pi folder name so these three things are very important if you will forget to give the correct name then it will not work so make sure this number one this path this part and this block one okay so these names must be correct so I will copy this and I will paste it here okay so this is my Project based directory I will just make sure this is my project folder name okay and this is where my settings dot file file exists so this is the name of the folder I will save this okay then I will move to next so I will enable my journeycon settings okay I think it's enabled so we can double check okay so we need to just follow the next steps okay now we need to set up nginx we are done with Johnny con setup so before you set up nginx make sure if there's any default file exists you need to remove it so I will first of all check and we can check if it yeah it's exist so you can remove this nginx by default file I will use command sudo remove r okay this file is removed so it's not there okay so we will deactivate our environment as well so we are done with our file removing so nobody had to create our new file so I will give the file name block so you can also change the name as well okay it's up to you so I will create this new file now and I will copy this content okay and I will paste it here one thing I want to tell you here this is server name because currently we are not going to install SSL but in my next video you can see how we will change this file to make it for https request enabled so for this it will be only run on HTTP protocol so this is server name by default if with this sign it's allow all the domains IP address connecting with our instance so for this we will leave it okay so this is our static file folder we need to make sure what is the name of our static files folder okay if it's static files then we will need to edit this path okay we will check it so then we need to make sure this the project folder name is correct okay these three things we need to figure out that everything is correct so I will save it okay then I will move to next I will enable this make sure this is the same file name we created above if your path name is not correct it will not work make sure this name is same as we created this okay so the configuration file name must be correct so I will copy this and then I will just go to my terminal okay so now we need to so we need to copy this command to load our static files the username will be your instance username so in my case it's Ubuntu so I will show you how you can find your username you can see this is my username to load the static files I will just run this command this will be Ubuntu okay the user has added no I have to run this command to start nginx okay now we have to come back to our project first of all I will go to my project we need to activate our digital environment okay then we need to run remaining two commands this one and this is our last command then we will test our application in browser okay so our server will be up so first thing we need to make sure which is static files so in our nginx configuration file when our name was static so I will update it otherwise the static files will not load so I have to go to my this was the command so I will just change the path here static files okay and then I will save it then I will just run the nginx to restart so it will collect all the changes in configuration file now we have to go to our IP address and we will see if the website is live or not okay we need to copy this public address and we need to paste in the browser so we can see our project is live wow this is we have done okay all the static files are also loaded so there is a new issue of CSS loading so what make mistakes you can make I can tell you no okay make sure you have added these two lines one this white noise in your install app configuration in your setting files and then this line to your middleware of your settings file of your project make sure you have added these two lines and the next thing is you make sure you have added this path these things in your main project folder directory in urls.pi file if you will add these two things first of all these things and then in the setting files you need to add this line and in the Middle where you need to add this so if you will add these two files you will not get the issue of static files okay your CSS will be loaded otherwise you will not see CSS loaded on your website so make sure you don't make these mistakes okay and in case if you are seeing any issue regarding uh your settings so you can just run this command in your terminal you will see where is the issue in your settings like in the deployments you can by mistake you can forget anything so make sure if you face any issue run this command and this command will tell you where is the issue okay so I think and the when you update any new changes in the code you can push you can you can push code to the GitHub and you can pull the code on your instance okay then you will need to just run these two commands to collect the new changes okay so we are done with our configurations and all these setup and our project is live as well so so make sure the static files are added everything is properly configured if you skip any point your CSS files button a lot load anymore so not make these configurations mistakes in your deployment and make sure you have after you have changes any in your code make sure to run these two commands so it will make the new changes live on your website okay so don't forget to subscribe my channel because it takes time to make a good videos so it will be uh appreciation from my followers so you can subscribe my channel as well thank you for watching my video
Info
Channel: CodeWithMuh
Views: 7,845
Rating: undefined out of 5
Keywords: deploy django project, deploy django project on aws, deploy django project on aws ec2, deploy django project on ubuntu server, deploy django app on heroku, deploy django app on netlify, deploy django app on digitalocean, deploy django project on aws ec2 instance server, nginx, gunicorn, deploy django project on github, django, python, deploy django
Id: 1D4mn_rO2cM
Channel Id: undefined
Length: 23min 13sec (1393 seconds)
Published: Thu Dec 15 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.