Hosted on a Pi!
In the last post I had set up the Raspberry Pi (after struggling for 3 days!) and now we have a computer running Linux. As I had planned, the next step was setting up a web server. Setting up the HTTP server is not necessarily part of the Raspberry Pi multiverse, its more from the Linux and Networking multiverse.
"Apache is the most popular web server available. A web server's job is basically to accept requests from clients and send responses to those requests. A web server gets a URL, translates it to a filename (for static requests), and sends that file back over the internet from the local disk, or it translates it to a program name (for dynamic requests), executes it, and then sends the output of that program back over the internet to the requesting party. If for any reason, the web server was not able to process and complete the request, it instead returns an error message. The word, web server, can refer to the machine (computer/hardware) itself, or the software that receives requests and sends out responses."
The above is one of the most simple and clear explanation of Apache / webservers I found online. Do read the entire post here.
Fortunately, installing a
httpd (HTTP standalone daemon process) on linux is pretty easy as opposed to the Pi setup. For Debian (Raspbian), just instal
apache2 and its dependencies using the following
$ sudo apt-get install apache2 php7.0 libapache2-mod-php
That's pretty much it! Once installed, the
httpd daemon (background process) is started automatically. Go to any computer connected on the same network and point your browser to
http://192.168.0.101 (this has to be your Pi's IP as found from the previous post). You should see a default html page like this one:
Well, thats basically done. I just hosted my first web page!
"Hey guys go to 192.168.0.101 to check my new page!"
My "site" still wasnt connected to the internet. All I could do was view it on my own computer and that too only if I was connected to the same network as the Pi. There were still many things left to be figured out.
"How does my laptop talk to the internet?"
Since websites like Facebook, Youtube, etc are basically applications presented as webpages, they need to be residing in some computer somewhere, same as the sample html page from
httpd resides in my Raspberry Pi.
Having not taken any coursework in networking, I had some homework to complete before I could move on. So here is a "long-simpleton-gist" of what I learnt from my Google stint on networking.
- The internet is a huge network.
- All connected computers are nodes in the network.
- All computers have addresses in the network called IP address (Internet Protocol address).
- Some big computers called DNS (Domain Name System) servers have addresses to (almost) all the public IPs.
- You have a house *read computer* but its not a part of this city *read internet*
- You need to be inside the city limits to be registered for others to visit you or you to visit others.
- Companies called Domain Name Registrars (like GoDaddy, Google Domains, etc) conduct registrations of your addresses. They help you convert your GPS coordinates to human readable street address and vice-versa (192.168.0.101 to/from www.mycoolsite.com)
- Unfortunately, the simplest way to enter the city is by paying huge companies called ISPs (Internet Service Provider) who can provide you with address registration, access to the city, provide houses in the city and most importantly point you to the right house given an address using the DNS.
- Some ISPs can even charge more for faster access to houses at certain addresses or wont let you visit certain houses unless you pay them more!! >:(
- You buy/lease a personal device called a Modem that is your direct connection to the ISP and indirectly to the city.
- Modern modems usually come with another inbuilt device called a Router that lets you share the city access with other users.
- The Router is another small computer (which mostly runs Linux!) which runs our DHCP service from the previous post that assigns temporary private IP addresses to all the users connected to it and the addresses may change periodically.
- The router/modem itself has a temporary IP (dynamic IP) address that is assigned by the ISPs so that it can connect to the internet city. So its the router/modem that indirectly connects you to the entire city.
- Our Raspberry Pi is one such house trying to get access to the city.
- We have our router/modem that it is connected to.
- And we have a surely have an ISP... who could possibly charge us more in the near future for reading content like this >:(
This is a basic setup of the internet city. Coming on how to visit the houses in this city.
Coming to the Raspberry Pi back from our story.
If you go back and try to connect the dots, I still had these problems to deal with:
- The address that the router will assign to my Pi is temporary and will change. So the city will never have a fixed address for my house.
- Even the ISP keeps changing my router's dynamic IP (unless I pay them more for a static IP).
- I needed to get a human readable address for my 'GPS-location' of 192.168.0.101.
Lets get to work
" ...coming soon... too tired at 4am .. I think I'll split this one up into 2, this one on networking and another one on the actual Pi stuff..."
Will be back soon..
"...Last night I got to read more on Networking and decided on writing a new post dedicated to networking. You might want it give it a go if you wish. A Martian's Guide to Networking. I'll be back with the setup of the Pi in the part 2 of this post."