Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Deployment
Lecture: 02-creating-our-linux-server

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now, the first thing we need to do to get started with our deployment is have somewhere to deploy it to. We could deploy to Heroku, or Azure, or AWS
0:10 or some other Platform-as-a-Service thing but what I want to show you is how to deploy to Linux. 'Cause if you know how to deploy to Linux
0:18 all those other things, maybe skip some steps and are just easier. But this gives you the most flexibility
0:23 to run your code, your web app, wherever you need and with the most configuration options available. We're going to use Digital Ocean for our host.
0:32 If you use something like AWS, EC2 or Lightsail, or Linode once we finish going through the process in this cloud portal
0:40 it's going to be, basically, all the same. So those are all recommended places you might check it out, you might try this
0:45 but I'm most familiar with Digital Ocean so I'm going to do that one here. So let's go and get started by creating a droplet.
0:52 We go to the market place and pick prebuilt machines like, I want to run a Disqus server on 18.04, and so on.
0:59 But I'm going to just focus right here on this. Now the default is the latest longterm support, Ubuntu. Alright, this is the latest.
1:06 But this is the latest longterm support and I recommend you keep a longterm support version. It's still pretty new.
1:12 So, let's go down and then choose our plan. These numbers might look big but if you just scroll over we have some pretty sweet ones.
1:19 We could choose the $5 or the $10 a month one and we'll just go with $5. With this server, we can handle several million
1:26 data-driven, Python-backed requests per month. No problem, for $5. And if you need more, you know go crazy, spend 10 dollars.
1:33 But this is the one we're going to do. We're going to not add backups block storage is like an external drive that you can have
1:40 that's independent of the lifecycle of your server. Like, you could destroy your server and still have this drive around, we don't need that.
1:46 I'm going to choose San Francisco, 'cause it's near me so it'll be nice and quick. If this was a real deployment I would choose New York, probably.
1:53 Because most of my customers would be either in the U.S. or Europe. And the east coast of the U.S. is a pretty good compromise, say
2:00 for people in California and people in Germany. Alright? We don't need extra stuff you might turn on monitoring here.
2:09 I'm going to check off a couple of the SSH keys that I have around. So a lot of SSH in and disable log in with the password
2:17 so it'll be, basically, impossible to brute force attack trying to log in. Let's give it a name like pypi-server
2:25 maybe with a dash, something like that. And, I think we're ready to go. Let's just click create and see what happens. Alright, the server is created.
2:34 I think it's just now starting to start up. So it might take a moment. We can click here, and click copy the IP address.
2:41 And put this away and now what we're going to is let's just try to login. So we come over here, we want to SSH as the root user
2:49 over to that IP address. Now on MacOS and Linux, SSH has been around for a long time this should work in the terminal no problem.
2:57 On Windows, it's just recently been added to the command prompt, I believe. And I think it might have been a part of PowerShell before
3:03 so you should be able to run it there. Let's try to SSH into it. It says, The first time, you've never seen this machine
3:10 and are you sure you want to exchange your keys with it? Yes, I do. And, it takes a moment we should be logged in. There we go, perfect!
3:18 Our machine is up and ready and we can do amazing things like ask what files are here or what directory we're in, things like that.
3:24 However, note there's a small little problem. Our server has come to life with 19 security updates and 41 updates.
3:34 Very first thing you should do, right away like immediately when you create this server is make sure you get the latest software patches
3:41 and install it. You do not want to run something on the internet that has security vulnerabilities. You want to minimize that.
3:47 So let's go do that now. We'll say apt update. That, okay, that's the latest software versions and it'll say apt upgrade to actually apply them.
3:57 So it's okay, we're going to do all this stuff here. And we're going to install when you see something like this we're going to install 4.15.0.51
4:06 the new kernel for Linux, so that's kind of a big upgrade and there's a bunch of other stuff going on here as well.
4:14 There you have it. It took maybe a minute and a half but, due to time shifting I was able to make that seem really short. So everything's installed
4:21 and if we log out, we can come over here and log back in and you'll see we have zero security updates but now a reboot, a system restart is required.
4:31 So don't forget to this step. We'll come over here and do a reboot. Notice right now we're running on what version? 4.15.0.50.
4:40 And when we come back, we should be on version 51 along with a ton of other updates. Now, because this is a full kernel update
4:46 it might take a few seconds longer but, you know, ten to fifteen seconds is what you should expect for, you know
4:52 the upper bound of how long this takes. Yes, perfect! Here we are, we have a brand new server a brand new server running on 51
5:04 zero updates, no reboot required and we're ready to go. So our server is up and running. Now it's up to us to configure it to be a web server
5:13 and to deliver our cool PyPI app.


Talk Python's Mastodon Michael Kennedy's Mastodon