WEBVTT
Kind: captions
Language: en

00:00:00.030 --> 00:00:04.620
Next we're going to update the allowed
host setting in our Django configuration

00:00:04.620 --> 00:00:10.590
to fix this bad request error that you
can see behind me open up the atom

00:00:10.590 --> 00:00:16.049
editor and load up the settings dot py
file in our project then scroll up to

00:00:16.049 --> 00:00:22.949
the top of the file and find the allowed
host setting here allowed hosts is a

00:00:22.949 --> 00:00:30.090
setting that allows us to enable access
via specific domain names it's a

00:00:30.090 --> 00:00:34.050
security feature to make sure that if
somebody just finds a random IP address

00:00:34.050 --> 00:00:38.820
for our server they can't access the
application unless they use a valid host

00:00:38.820 --> 00:00:43.379
name so we need to specify the host
names that we want to allow to connect

00:00:43.379 --> 00:00:48.140
to our server in the allowed host option

00:00:48.140 --> 00:00:49.739
the host name that we need to add is

00:00:49.739 --> 00:00:54.420
the host name for our server which is in
the ec2 configuration here and is the

00:00:54.420 --> 00:00:56.740
public dns option

00:00:56.740 --> 00:01:00.210
so copy the contents of that and then open up the atom editor

00:01:00.210 --> 00:01:05.549
and we're going to paste it as a string
into this list here we also need to add

00:01:05.549 --> 00:01:12.900
the local host so that it still works on
our vagrant server so in a second item

00:01:12.900 --> 00:01:18.320
in this list type 127.0.0.1

00:01:18.320 --> 00:01:20.280
I'm going to break this out into separate lines to

00:01:20.280 --> 00:01:27.829
keep it within the character limit and
then make sure you save the file now

00:01:27.829 --> 00:01:33.990
that we've made a change to the project
we can demonstrate how to update changes

00:01:33.990 --> 00:01:36.420
on our server after we push them to github

00:01:36.420 --> 00:01:41.310
let's start by committing and pushing
this change to github so open up the

00:01:41.310 --> 00:01:45.600
terminal and make sure you have a window open that is on a local machine and not

00:01:45.600 --> 00:01:48.160
connected to our server

00:01:48.160 --> 00:01:52.649
select our project directory then type git add dot

00:01:52.649 --> 00:01:57.810
to add any additional files and then type git commit - am and we'll add the doc

00:01:57.810 --> 00:02:02.840
string added allowed hosts

00:02:02.840 --> 00:02:06.570
then type git push origin to push the changes up to

00:02:06.570 --> 00:02:08.560
github

00:02:08.560 --> 00:02:10.649
now that the changes are on github we

00:02:10.649 --> 00:02:13.650
can run our update script on the server to

00:02:13.650 --> 00:02:20.579
pull the latest changes so go back to
the server that is connected via SSH if

00:02:20.579 --> 00:02:26.159
it's disconnected then just run the SSH
command again to connect back to the

00:02:26.159 --> 00:02:30.720
server and we're going to navigate to
the location on the server where our

00:02:30.720 --> 00:02:39.020
project files are stored so type CD forward slash usr forward slash local forward slash apps

00:02:39.020 --> 00:02:43.900
forward slash profiles rest api and hit enter

00:02:43.900 --> 00:02:45.860
if you type LS you should see all of the

00:02:45.870 --> 00:02:52.109
project files here and what we're going
to do is we're going to run sudo sh dot

00:02:52.109 --> 00:02:57.120
forward slash deploy forward slash
update

00:02:57.120 --> 00:02:58.829
this is the command that will run

00:02:58.829 --> 00:03:04.319
the update script that will update the application based on the latest

00:03:04.319 --> 00:03:10.260
github changes hit enter on that and it
should pull the latest changes down and

00:03:10.260 --> 00:03:14.713
then run all of the commands necessary
to restart the server

00:03:14.713 --> 00:03:15.900
okay you can see

00:03:15.900 --> 00:03:20.879
that the script has finished running so
let's go to our browser and let's open

00:03:20.879 --> 00:03:26.760
up the tab that we got the bad requests on and hit refresh now you

00:03:26.760 --> 00:03:31.349
can see it says not found because
there's no root mapped to the base of

00:03:31.349 --> 00:03:37.650
the URL so we're going to just add
forward slash API forward slash and you

00:03:37.650 --> 00:03:41.360
should see the root of our API

00:03:41.360 --> 00:03:43.349
you should also see if you put forward slash

00:03:43.349 --> 00:03:46.220
admin the admin page

00:03:46.220 --> 00:03:49.560
the only thing left to do now is to create a super user on

00:03:49.560 --> 00:03:55.160
our server so that we can log into it
using our user account

00:03:55.160 --> 00:03:56.060
so open up the

00:03:56.069 --> 00:04:01.979
terminal and make sure that you are in
the forward slash USR slash local slash

00:04:01.979 --> 00:04:06.510
apps slash profiles REST API and then
we're going to run the following command

00:04:06.510 --> 00:04:09.220
to add a super user

00:04:09.220 --> 00:04:17.699
we're going to run sudo env slash bin slash Python and then

00:04:17.699 --> 00:04:26.280
we're going to run manage dot py create
super user and hit enter

00:04:26.280 --> 00:04:32.910
then enter an email address I'm going to put mark@londonappdev.com hit enter and

00:04:32.910 --> 00:04:36.870
then a name I'm going to put mark and then
for the password I'm just going to put

00:04:36.870 --> 00:04:42.120
password one two three but make sure you
put a secure password when you create

00:04:42.120 --> 00:04:47.160
this because your site will be publicly
accessible which will open it up to be

00:04:47.160 --> 00:04:48.560
attacked

00:04:48.560 --> 00:04:51.300
so once you've entered the password hit enter I'm going to re enter

00:04:51.300 --> 00:04:57.240
the password hit enter I'm going to put yes and now you can see the super user has been

00:04:57.240 --> 00:05:03.980
created so let's test this I'm going to
go over to the Django admin type mark@londonappdev.com

00:05:03.980 --> 00:05:08.400
password password 1 2 3 hit enter and you can see

00:05:08.400 --> 00:05:14.640
that I've logged into the Django admin
and now our app is working as expected

00:05:14.640 --> 00:05:21.200
so that's how you deploy the app to AWS
on an ec2 instance

