Deploy a Django Web App to Amazon EC2 Instance | 2024

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
where are you [Music] hi and welcome to this YouTube video in this video I will teach you how to deploy a jungle project to an AWS ec2 instead so the first step that we need to take is make sure that our projects or your project is already on a GitHub reposition now the reason why we need to do this is because it's going to make our life easier when we want to deploy this project to the instance so make sure that you just deploy um your projects to GitHub so we may proceed so the next step you need to take is log into your uh Amazon dashboard and you need to search for ec2 uh right here so just click it and when you click it you'll be brought to this page so just click instances so this is just going to take you to where you are going to see all your instances so right now I have uh just one running so I would like to launch a new instance because we want to host this website this jungle project on a new insta so click launch instances so the first thing that we need to specify on this page is the name of this server now you can decide to name This Server anything you want I'm just going to call it um tutorial now after specifying the name of this tutorial we need to select an operating system that we want to prepare these projects to and it's the operating system that will run on This Server so we're just going to go with uh Ubuntu now in next uh step that we need to take is that we need to make sure that we are seeing a type of T2 micro under the instance type so just make sure that you have T2 micro because it's the free tier so we can have an instance for free running on aw so after doing that we need to scroll down to network settings and you need to make sure that create Security Group is click and allow SSH traffic from so you need to make sure that these two things are ticked now the next uh step that we need to take is yeah I think that is pretty much it so let's click launch instance now it's going to ask us to create a keypad but let's just click create without keyplay because we uh we want SSH into the server as we will be working directly on the cloud and I will show you how we're going to do this so just click proceed without keypad and take it here so after doing that just click launch instance so when you click that it's going to launch the instance for thank you so let's now go to instances so when we come back to instances you'll see that uh the instant state is pending and then the status check is still being it has not been verified so what we need to do right now is wait for the instant state to say running and we need to wait for the status check to see two over two passed so you can do that by constantly refreshing so I'm just going to pause here and wait for the instance to finish setting up okay so right now um we can see that the instance date says running and the status check says two over two checks passed to write our our instance has been successfully created for us what we need to do right now is we need to connect to this instance so click the instance that you have created which is tutorial that I created and once you click it I head over to the top here and click connect so once you click connect just scroll down a bit and the way you see connects just click that button so it's going to open um this web terminal for us that we can use to interact with our server which which we just create so let's just clear out uh the screen and do that by typing c l e a r which is Click now uh what we need to do first is that we need to update this server uh so what's uh the command that we're going to run is sudo app Dash gets please update so once you run that command it's just going to update this server for you now I had already gone ahead and done some testing so that's why the prompts being printed are very short but for you it's probably going to take a while for server to update now that's why it took a very short while for Mentor now the next step that we need to get here that we need to take is that we need to clone this GitHub repository which we had created here into this ec2 instance so I want you to head over to your repository click this drop down right here and copy the link so after copying it head back to your ec2 instance let's clear the screen and run the command git clone and then paste that link but once you do that it's just going to clone and the repository into this ec2 instance for us and if I type LS which is to see the contents right now we can see that a new folder has been created called Django channels chat app which is the exact same name of my repository so right now I have successfully cloned the repository into server so let's CD into this uh folder and when I say LS you see the content you can see there is the exact same contents as the one on repository so we have the requirements templates and all that and it's the exact same thing getting displayed right so let me clear out the screen The Next Step that we need to take is we need to install the dependencies that our projects need dependencies like obviously Django and other um libraries that probably used that is why I have a requirements file in my repository that I can install for now we know that in order to install um in order to install packages we need to use pip which is the package install manager for python now in order to um do this we first need to install people so uh we need to run a command right now to install people to run the command sudo this app please install uh install space python 3. peep space Dash y so once you run this command it's going to just install people now the reason why again uh the reason why the problems are short is because I already have Pip installed as I went ahead and did some testing if while you were installing you saw a strange prompt just show up on the screen you can just click exist and that will get rid of let's clear out the screen right now so right now we have a heap installed the next step that we need to take is we need to install all the requirements for our project dependencies so I am going to run the command pip install so let's write pip3 install Dash R requirements Dot txt now once you run that command it's going to install the requirements for you but you can see I had already installed this requirements earlier so just hit back and wait for it to install all the requirements after doing that let's just clear out the screen now if if you haven't made migrations earlier that is if I go to my reposition right now you can see I have a database here now that comes from a project that I worked on earlier it's a channels uh chat app that I worked on so these are just the basic modules and I had already made the migrations and migrated the changes to the database but if you haven't done that just make sure you run make migrations and and if you also don't have a super user Make sure you create a super user I am going to assume you know how to do those things so right now what you now need to do next is run our server to run python manage.pi run server it's giving us an error let's do Python 3 minus the pi run server so once we run that command it's going to run our server for you well I want you to take note of something you'll notice that right here we have the local development server which is a local host being returned back to us now that doesn't make sense because we want to host our website in such a way that anybody with the link in in any part of the world and access this websites but we are being given localhost which is a local development so basically nobody can access it except us on our local machine so what we need to do right now is we need to make some changes so let's first break out of terminal using Ctrl C and then let's uh run the following command python I would like to clear my timing outfit let's run Python 3 manage.pi run server and then once type 0.0.00 we'll learn eight thousand so while we are doing this is because we will need to set um in order for in order for us to have this uh jungle project or Django app globally available to anybody we're going to need to go to the security groups and set an inbound Rule and then we will need to point to Port 8000 so that we will be able to connect to um our Django project or our Django app on Port 8000 from um the server so you are going to see how we are going to do this so what we need to do right now is head back to the ec2 instance and then uh so I'm just going to head back to the and then I want you to click that instance and if you scroll down a bit you'll notice that we have this public ipv4 address if we open that link in a new tab now when you open this link I want you to replace the https with HTTP and then visit it on Port 8000 so it's going to be colon 8 000. now once we try uh visiting this link you are going to notice that nothing is going to happen now nothing is going to happen because we need to set up the inbound rule which is going to point to our app uh which is going to point this ipv4 address to our app and to our Django application on Port 8000. so we need to head back to the insta now this is just going to load and eventually it's going to stop loading and display an error in the brow so we need to head back to um the browser and then we need to click this ID instance ID of our ec2 so once we do that I want you to scroll down a bit and then under the security tab you'll notice that we have inbound rules and outbound rules so what we need to do here is that we need to create a new uh inbound rule so you'll see this URL here for security groups click this URL and you will be brought to this page right here so what we need to do is say edit inbound rules once you click that just click add rule so we need to add a new uh inbound rule so under here or the port range for the ports range since we would like to connect to about 8 000 we're just going to type in 8 000 here and then for the uh Source info we're going to select zero points okay if I zoom in here I'm zoom out I mean we need to select 0.0.0 points because I you know we had run the server earlier on that particular URL which is here so we need to select that so basically it means that we can connect to our Django app from anywhere or from anywhere on Port 8000 that is why we need to do that's why it's saying anyway as soon as you can connect over Django up on point 8000 from once you've done that just click save rules now uh once that has saved we can head back to the URL and reload now you'll notice that we are getting an error saying invalid HTTP blah blah blah so this is purely coming from Django now the reason why we're guessing this arrow is because um in the installed apps in our Django projects if I go to my settings right now let me just go to my settings on the Repository if I go to my settings I hadn't specified um allowed host right here so it's giving us an error so now we can solve this simply if we head back to the um terminal right here let's break out of the server now once you break out of the server we need to edit our settings dot Pi file in our project folder now if we edit it on our project on GitHub we'll have to reclone a repository and uh that's just a longer process so we can do this in a shorter way if I say let me just clear my screen first if I say LS here you can see that we have the charge project and inside the chats project we have our the settings.pi file so I'm going to say Nano space chart projects forward slash settings plus pi so I would like to edit this uh file this is my settings.pi file right here so if I scroll down a bit I would see a loud host now what Nano allows us to do is basically to just edit our code inside the terminal so in here I'm just going to type in Star which means any URL or any yeah any URL or any domain can host our website so in order to save these changes and exit this all we need to type first is Ctrl o press enter and then Ctrl X so once we've done that all we simply needs to do is run the server again so I am going to run the server on this URL area that we have done so once that is running let's head back to URL and refresh now what do you know the project is uh showing and everything is working perfectly well right now so we've been able to host our Django project on an Amazon ec2 instance that is all for today today guys if you found this video helpful please don't forget to like share and subscribe
Info
Channel: THE PROTON GUY
Views: 5,957
Rating: undefined out of 5
Keywords: Django, AmazonEC2, WebDeployment, AWS, DjangoTutorial, CloudHosting, DjangoApp, EC2Instance, PythonWebFramework, DjangoDeployment, AWSservices, BackendDeployment, WebApplications, DjangoProject, ServerSetup, WebHosting, PythonDjango, EC2Configuration, AWSHosting, DjangoProduction, VirtualServer, CloudServices, WebServers, DjangoBestPractices, ElasticComputeCloud
Id: tryZWxTVDks
Channel Id: undefined
Length: 16min 26sec (986 seconds)
Published: Sun Sep 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.