1 00:00:00,000 --> 00:00:09,287 2 00:00:09,287 --> 00:00:11,120 DAVID MALAN: So for this problem set, you're 3 00:00:11,120 --> 00:00:13,236 going to implement your very own web server. 4 00:00:13,236 --> 00:00:16,110 We've provided you with a bit of skeleton code that gets you started, 5 00:00:16,110 --> 00:00:17,818 but ultimately, you're going to finish it 6 00:00:17,818 --> 00:00:19,940 up so that it actually implements the ability 7 00:00:19,940 --> 00:00:23,980 to serve up web pages, both static content and also dynamic content, 8 00:00:23,980 --> 00:00:25,090 via PHP. 9 00:00:25,090 --> 00:00:27,380 >> Let's take a look, first by way of the staff solution, 10 00:00:27,380 --> 00:00:29,390 at what the final result is going to be. 11 00:00:29,390 --> 00:00:33,420 I'm first going to run tilda cs50/pset6/server 12 00:00:33,420 --> 00:00:36,330 and then dash p to specify a port and then a number 13 00:00:36,330 --> 00:00:38,410 like 8080, which is pretty common. 14 00:00:38,410 --> 00:00:40,420 And then the name or the path to directory 15 00:00:40,420 --> 00:00:43,360 that I want to use as the web server's route, where all of the files 16 00:00:43,360 --> 00:00:44,680 are going to be served up from. 17 00:00:44,680 --> 00:00:46,180 I'm going to go ahead and hit Enter. 18 00:00:46,180 --> 00:00:49,010 And you'll see in color text here that the web server is 19 00:00:49,010 --> 00:00:52,450 using my public directory and it's listening on port 8080. 20 00:00:52,450 --> 00:00:55,300 Now let's go over to a web browser and actually try 21 00:00:55,300 --> 00:00:56,855 to connect to this website. 22 00:00:56,855 --> 00:00:59,230 Notice in the bottom right hand corner of your appliance, 23 00:00:59,230 --> 00:01:02,040 that there's been all this time an IP address. 24 00:01:02,040 --> 00:01:03,890 That's a unique identifier for your computer 25 00:01:03,890 --> 00:01:06,050 that identifies it so that you can access it 26 00:01:06,050 --> 00:01:08,261 via web browser or any number of other tools. 27 00:01:08,261 --> 00:01:10,760 So I'm going to go ahead and open up Chrome in the appliance 28 00:01:10,760 --> 00:01:19,250 and I'm going to visit http://172.16.254.133 and then 29 00:01:19,250 --> 00:01:20,960 colon 8080. 30 00:01:20,960 --> 00:01:24,344 And the colon's important because if you don't specify that port that I also 31 00:01:24,344 --> 00:01:26,260 specified at the command line, you're actually 32 00:01:26,260 --> 00:01:28,390 going to be talking into the appliance's own web 33 00:01:28,390 --> 00:01:30,850 server called Apache, which is built into it. 34 00:01:30,850 --> 00:01:33,610 But today we want to focus on our own web server. 35 00:01:33,610 --> 00:01:36,550 >> So now when I hit Enter, you'll notice that 501 36 00:01:36,550 --> 00:01:38,380 Not Implemented comes up because I've tried 37 00:01:38,380 --> 00:01:41,000 to access a directory, not a particular file. 38 00:01:41,000 --> 00:01:43,980 Indeed, if you look over to the left in my terminal window, 39 00:01:43,980 --> 00:01:46,690 you'll see that while listening on port 8080, 40 00:01:46,690 --> 00:01:52,600 the web server saw a request for GET/HTTP/1.1 and then the web server 41 00:01:52,600 --> 00:01:56,680 responded, as pictured here in red, with that 501 Not Implemented. 42 00:01:56,680 --> 00:01:59,270 >> Curiously though, there's also this second line in white, 43 00:01:59,270 --> 00:02:03,355 GET/favicon.ico HTTP/1.1. 44 00:02:03,355 --> 00:02:06,230 Now I definitely didn't do that myself, but it turns out that Chrome, 45 00:02:06,230 --> 00:02:09,910 like a lot of browsers, will presumptuously assume that your website 46 00:02:09,910 --> 00:02:13,170 is supposed to have a little graphical icon up in the tab or next 47 00:02:13,170 --> 00:02:16,380 to the address bar, like a Harvard crest or something along those lines, 48 00:02:16,380 --> 00:02:19,425 and so it's just guessing by way of this default file name, 49 00:02:19,425 --> 00:02:21,800 that you might have a file like that too, which we don't. 50 00:02:21,800 --> 00:02:24,650 And so 404 Not Found gets spit back. 51 00:02:24,650 --> 00:02:26,120 >> Well now, notice this. 52 00:02:26,120 --> 00:02:29,440 In addition to visiting this address inside 53 00:02:29,440 --> 00:02:34,940 of the appliance, 172.16.254.133:8080, but your IP address, to be clear, 54 00:02:34,940 --> 00:02:35,910 will be different. 55 00:02:35,910 --> 00:02:39,690 Notice that if I go on my Mac or my PC to my own browser 56 00:02:39,690 --> 00:02:43,200 and visit that same URL, I can see from my own preferred browser 57 00:02:43,200 --> 00:02:46,340 whether it's Chrome or Firefox or IE or something else, exactly 58 00:02:46,340 --> 00:02:47,550 the same results. 59 00:02:47,550 --> 00:02:48,130 >> OK. 60 00:02:48,130 --> 00:02:51,820 Let's actually visit a URL that's known to exist in that public directory. 61 00:02:51,820 --> 00:02:56,890 Namely, the IP address colon 8080/cat.jpg. 62 00:02:56,890 --> 00:02:57,930 Enter. 63 00:02:57,930 --> 00:02:59,470 And there, indeed, is Happy Cat. 64 00:02:59,470 --> 00:03:03,340 I know in advance that there's also a cat.HTLM file, so if I hit Enter, 65 00:03:03,340 --> 00:03:04,469 I see that one as well. 66 00:03:04,469 --> 00:03:06,260 And notice, in the meantime, on the left we 67 00:03:06,260 --> 00:03:08,176 have a whole bunch of green outputs signifying 68 00:03:08,176 --> 00:03:13,360 that these were 200 statuses, which means they were OK. 69 00:03:13,360 --> 00:03:18,294