#100DaysOfWeb in Python Transcripts
Chapter: Days 89-92: Deploying Python web apps to Linux
Lecture: Getting the Python source files on the server

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The next thing we need to do is get our source files on the server and things like that. So we're going to create a root based
0:08 this is on the root of our drive a folder called webapps. Call it whatever you want. Just making this up in a way that works well for me.
0:15 Then we'll have logs section and we're also going to have a web app source code sub folder here but we're going to use git clone to create that.
0:24 So let's just start by creating the structure, like so. I'm going to run that, and now you can see we're in /webapps. There's nothing in here.
0:33 Oh I like to use tree to explore stuff. So we'll put tree on here. Then you can do things like tree your home, and tree what it is.
0:40 We'll see that in a moment. Okay, now what we're going to do is we're going to create a Python virtual directory. Now there is Python on here.
0:47 We set that up already but if you ask which Python3, it's the system one and we don't want to mess with the system.
0:56 Instead, we'd rather create a Python virtual environment that's entirely stand alone that we can upgrade, we can install stuff to.
1:02 It won't affect the overall system Python 3. That'll be a little easier for us. It won't require sudo, and all those kinds of things.
1:08 So the next thing we want to do is come over here and create this virtual environment just using that command.
1:14 We're going to activate it, we'll go to install or upgrade pip and setuptools. So let's just do those steps right now.
1:21 As you can see, pip is super out of date so is setuptools. I see that. It also asks which Python again. Now we have the one in our virtual environment.
1:30 Okay, super. So that's a good step. We're also going to install a couple of tools. First we're going to need uWSGI, obviously. That's the other part.
1:39 We already installed Nginx. That's a system thing. uWSGI is a Python thing. So we'll install it here. Just a heads up, installing uWSGI
1:46 can take a little while. Super, we installed the latest uWSGI successfully. So if you try to run it, it's not going to run
1:53 'cause we haven't configured it yet but we're pretty much good to go there. The last thing are two little utilities. One called HTTPie, HTTPie, I guess
2:02 I don't really know how to say it correctly and that lets us do requests. Its like cURL or Wget but it's much nicer and it's a Python library.
2:09 So we'll install that. That'll let us test our app as we install, as we kind of get our servers up and running
2:15 and we're going to use Glances, which is a really awesome way to get a quick look at how your server's running
2:20 where the process is, how much memory they're using CPU, et cetera. So install those two things. So just to show you, we can say http talkpython.fm.
2:32 We see it downloads it and even color codes it for us. That's pretty sweet and we could run Glances and see what's happening on this server.
2:39 Here if we make it better, you can see a little better. Get little graphs. So the CPU, not much is happening. Mostly Glances itself here is doing that.
2:48 Doing all the work. And you see what else is running. We'll have more processes running as we set up uWSGI and Nginx.
2:54 So we get our IO time, our memory used, memory free all that kind of stuff. So that's it, all of our Python stuff is set up and configured.
3:04 Next thing to do is to get our source code our web app source code on the system and we're going to just do that by git cloning
3:11 100daysofweb-with-Python-course 'cause that's really long. We're going to put it into a shorter directory. It's called app_repo.
3:18 So we'll just do those two things. Now because while I'm recording this course my GitHub repo is private I need to log in but if you do this later
3:27 you won't have to give your username and password because I'll have made that repo public. So there we go, we've not gotten all of our files here.
3:36 That's not super helpful. So here you can see we've checked out our app_repo. It's got the days, and here's the code that we got all ready to run.
3:46 We're going to mess with that in a little bit. Here's our log file. We're going to put our app logs here and whatnot. And then our virtual environment.
3:53 So we're just about ready to get started. We got our source code here. We've got our Python set up and we've got our Linux set up.
4:00 The last thing to do, before we get onto actually configuring the web app so it'll run let's just do one quick little thing.
4:06 So notice if I come over here and I exit and I log back in and I ask which Python, or which pip, or whatever it says the system one
4:13 but I never really want to mess with that. I almost always when I come to the server care about configuring the web app.
4:20 So here's a cool little trick, which it might be helpful. Got to find the right directory. So hold tight. There we go. So we want to run this command
4:30 at the very end of our login. So let's put in our RC file. Now if we exit out of the server and we log back in notice our virtual environment ready
4:43 so any commands we give it or whatever will be targeted at the virtual environment that our web app is using.
4:49 Which, like I said, is almost always the reason we're logging into the server is to configure our web app. So I like to make sure, by default
4:55 I don't accidentally install something or change something about the system Python and the easiest way to do that is just to have it always activated.
5:03 Of course, if for some reason you need the system Python you could just deactivate real quick and you're back to system file.
5:09 Okay, super, so now our system is set up our Python environment is set up. We just need to put the configuration files in place
5:18 so that our Python code can actually run.

Talk Python's Mastodon Michael Kennedy's Mastodon