Install, Discuss, and Configure a Web Server

We will install the Apache web server, which is a very common linux web server (according to this website, Apache is used on over 1/3 of all known websites on the internet!). To do this, run sudo apt install apache2 in the ubuntu login on the Raspberry Pi. Once that completes then you can launch a browser from your laptop or desktop and in the URL window, type the IP address of the Raspberry Pi. You should see the "Apache2 Ubuntu Default Page", which means your web server is installed correctly and working! Any computer on your network can view this webpage.


How does a web server work? By default, a web server just serves files. When you entered the IP in the URL of your browser and hit 'Go', your browser sent a request to the Apache software on the Raspberry Pi for the default file (because you did not specify a file in the URL). The default file is called index.html. On the Raspberry Pi, the default location for all web files, known as the DocumentRoot, is /var/www/html. So when the apache software received this request, it looked in /var/www/html and returned the index.html file located in that directory. Your browser received this file and displayed it. If you look in /var/www/html, you will see this file:

ubuntu@ubuntu:~$ ls /var/www/html



If the web server just serves files, how do we make interactive web pages? There are a couple of ways to make web pages interactive. For example, Javascript is a popular way to write an interactive web page that runs within your browser. This way, the server only needs to serve the web page once, and the Javascript code runs in your browser and reacts to your clicks. However for this tutorial, we will configure the apache web server to execute programs on the Raspberry Pi that will dynamically produce a web page based on user input. This approach is useful when you have data on the server that you want to incorporate into the web page that is produced.

NOTE: this style of website design is fine for home and club networks and private scouting networks, but the Raspberry Pi will only be able to handle so much traffic. We have even observed some occasionally slow web responses when scouting with 6 tablets connected to one Raspberry Pi at competitions. It hasn't been a problem for scouting, but I just want to set proper expectations on what you can do with this capability.

Early in the development of the internet, a Common Gateway Interface or CGI was defined so that web pages could connect users with other programs or data running on a web server. A CGI script is a program that can accept input and produce a web page based on that input. Web servers can be configured to run CGI scripts, so that if a local CGI script was requested, it would execute that CGI script and return the output. This is how we will create interactive web pages in this tutorial.