Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Deployment
Lecture: Configure the server
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
All right, so let's just start running some commands on the server. We need to install a couple of dependencies to make sure we have Python 3 in place.
0:09
Now, if we go to our server we should already have Python 3 in because we chose a new version of Ubuntu
0:15
we got 3.6, which is pretty modern, that's nice. However, that doesn't give us things like pip for example.
0:24
Or pip3 is really what we are after or Python3 -m venv. Oh this one actually works sometimes the older one, it didn't come with it.
0:34
So there's these various operations like super simple stuff we need like pip that aren't there. So let's install our build essentials
0:39
and git that's not already there, Python3, pip and the dev tools and so on. So we're going to install, let's do those three right there.
0:51
Yeah, looks like the last one didn't run, okay, good. So those are all set up. Now we're going to install Nginx.
0:58
Great, so it looks like Nginx got installed okay. Now, one of the things that's nice to set up gzip support in uWSGI is to help our files over the wire
1:08
be a little shorter, be a little smaller a little quicker but we need some dependencies and so we'll just drop those in there.
1:18
Okay, great and then let's go ahead and set up this thing called Fail2Ban and that means if somebody tries to continue to login
1:24
and they keep failing and failing it's a system service that will block that IP address from attempting to log into our servers.
1:30
So, this is always nice to have around. And while we're at, let's turn on a software firewall and we'll say we want to listen to SSH traffic
1:42
HTTP and HTTPS and nothing else. Those are only things we want to let in and on this one we're going to be carefully watching
1:50
to make sure people don't abuse it. So we're going to enable this. It says are you sure you want to enable it?
1:56
If you don't put 22 in here, you're never coming back. We did, luckily so it's active. Let's just logout one more time and make sure
2:03
we can get back in. Good deal. Now, one of the things we're going to do is some Git commands and it's super annoying to me
2:10
that I've go to keep typing them over and over every time. My password is incredibly long. So let's just run this command here which says
2:19
once we type it as long as we don't reboot or anything for whatever however many seconds 720,000 is
2:26
just remember this so I won't have to type it again, great. And also, we'll put our name, our e-mail and our name
2:33
if we're going to do any checkins at all, we have to do this. Same for the name. Okay, so Git should be up and running
2:43
and we should have already installed it from when we did our dependencies before. I think I saw it already there.
2:48
Now what we want to do is actually go and create a section on the hard drive where we check out our apps, where we have our logs
2:56
and things like that. So let's just go do all those things. There we are, great. Now we're going to do a couple of things.
3:03
We're already here. We're going to create a virtual environment. Now this virtual environment is just like the virtual environments we've been using
3:11
throughout the course but this one is going to be on the server. Now the server is technically just dedicated
3:16
to this web app and we could use the system-wide install in sudo pip and all that but I find that we have a little more flexibility
3:24
if we create this and we decide something goes wrong and we need to recreate it, we haven't busted the server
3:30
so we're going to create a little virtual environment and we're going to activate it. Notice the prompt change to venv
3:40
and then we're going to pip install -U pip and setuptools. Those are probably out of date. Let's make sure they're updated.
3:49
There you go, much better. pip 10 setuptools 40. So we've already done that step. Let's go and install a couple of management tools
3:56
that are really sweet, httpy, which will let us it's kind of like curl but nicer. And then Glances lets us look at the process. All the processes.
4:07
So we'll install this into our virtual environment. So now we can run Glances, see what's going on on the server.
4:15
Make it a little bigger, even get progress bars. So you can see over here, Glances is running. Let's sort by memory, press M for that.
4:23
And we probably see things like Fail2Ban over here. Yeah, here's our Fail2Ban server that's already running from before. Here's our Glances.
4:32
Not a whole lot else is going on. Because we haven't done anything with the server. It's about to get interesting though.
4:37
Let's do one more thing, see this command source or dot venv/bin/activate? If we log out and we log back in we ask which Python, it's the system one
4:49
it's not the one that controls our web app. What's the chances that we want to modify the system one versus the one that controls our web app
4:55
when we log in here? Zero. So let's do this. Let's go in here, and at the bottom of our bash let's have it activate.
5:09
So now when we log out and log back in we ask which Python, oh yeah. So now, just by virtue of logging in
5:16
we've already activated the virtual environment that we're almost always going to be working with. There may be some drawback to some weird command
5:23
you need to run but I find this is much nicer, you won't forget to enable and use that virtual environment. Alright, we're very, very close
5:31
the next thing we need to do is get our code over here and start configuring it and making it run. We'll do that next.