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