DAVID MALAN: So for this problem set, you're
going to implement your very own web server.
We've provided you with a bit of skeleton code that gets you started,
but ultimately, you're going to finish it
up so that it actually implements the ability
to serve up web pages, both static content and also dynamic content,
via PHP.
>> Let's take a look, first by way of the staff solution,
at what the final result is going to be.
I'm first going to run tilda cs50/pset6/server
and then dash p to specify a port and then a number
like 8080, which is pretty common.
And then the name or the path to directory
that I want to use as the web server's route, where all of the files
are going to be served up from.
I'm going to go ahead and hit Enter.
And you'll see in color text here that the web server is
using my public directory and it's listening on port 8080.
Now let's go over to a web browser and actually try
to connect to this website.
Notice in the bottom right hand corner of your appliance,
that there's been all this time an IP address.
That's a unique identifier for your computer
that identifies it so that you can access it
via web browser or any number of other tools.
So I'm going to go ahead and open up Chrome in the appliance
and I'm going to visit http://172.16.254.133 and then
colon 8080.
And the colon's important because if you don't specify that port that I also
specified at the command line, you're actually
going to be talking into the appliance's own web
server called Apache, which is built into it.
But today we want to focus on our own web server.
>> So now when I hit Enter, you'll notice that 501
Not Implemented comes up because I've tried
to access a directory, not a particular file.
Indeed, if you look over to the left in my terminal window,
you'll see that while listening on port 8080,
the web server saw a request for GET/HTTP/1.1 and then the web server
responded, as pictured here in red, with that 501 Not Implemented.
>> Curiously though, there's also this second line in white,
GET/favicon.ico HTTP/1.1.
Now I definitely didn't do that myself, but it turns out that Chrome,
like a lot of browsers, will presumptuously assume that your website
is supposed to have a little graphical icon up in the tab or next
to the address bar, like a Harvard crest or something along those lines,
and so it's just guessing by way of this default file name,
that you might have a file like that too, which we don't.
And so 404 Not Found gets spit back.
>> Well now, notice this.
In addition to visiting this address inside
of the appliance, 172.16.254.133:8080, but your IP address, to be clear,
will be different.
Notice that if I go on my Mac or my PC to my own browser
and visit that same URL, I can see from my own preferred browser
whether it's Chrome or Firefox or IE or something else, exactly
the same results.
>> OK.
Let's actually visit a URL that's known to exist in that public directory.
Namely, the IP address colon 8080/cat.jpg.
Enter.
And there, indeed, is Happy Cat.
I know in advance that there's also a cat.HTLM file, so if I hit Enter,
I see that one as well.
And notice, in the meantime, on the left we
have a whole bunch of green outputs signifying
that these were 200 statuses, which means they were OK.