You will be building a web server using Ubuntu and Apache.
You will be learning to create a dynamic web application using CGI.
Part 1.
You will be creating your own personal web server for use during the course.
Your web server will be built using the LAMP
software stack consisting of Linux (operating system), Apache (web server), MySQL (database), and PHP (server-side scripting).
In this lab, you will be setting up Linux and Apache.
We will configure MySQL and PHP in future labs.
Pick a machine in the networking lab
Boot from an Ubuntu CD and install operating system (or reuse a machine you built last term in Networks).
Choose whatever you like for server name, username and password.
However you will need to tell me the details including password.
Ensure the operating system has all the latest updates:
sudo apt-get update
sudo apt-get upgrade
Install the Apache web server using Ubuntu's package management software apt-get:
sudo apt-get install apache2.
Update the Apache configuration file:
Configuration is via the httpd.conf file in conf subdirectory.
ServerName needs to be changed to match your chosen server name.
Test out the web server:
Start/stop/restart using the script bin/apachectl.
Open browser to localhost to test.
Test making a change to the main web site page at htdocs/index.html.
Familiarize yourself with logging:
Log files live in logs/.
Test out the CGI (Common Gateway Interface):
Figure out how to load the test-cgi script that lives in cgi-bin/.
If something goes wrong, check the log files.
You may have to adjust permissions to get things working.
What username/group does Apache use when serving web pages? Use ps -Af to investigate.
Part 2.
One way a web server can provide dynamic content is by shelling out to an external program or script via CGI.
You will be creating a simple web application that can store name/value pairs.
The pairs are associated with a particular filename.
You can store the pairs in the file in any way you like so long as it behaves as specified below.
Create two HTML pages get.html and set.html.
The get.html page works as follows:
Contains a form with two fields, the filename and the field name.
On submission, the form calls your CGI program and returns the matching value.
If no matching name is found, it returns a blank page.
If something goes wrong (e.g. the filename doesn't exist on the web server),
print out "ERROR," followed by a description of the problem.
Names are case sensitive and must match exactly.
Name and values are no more than 255 ASCII characters in length.
If a file contains multiple pairs with the same name, return the value of the last pair in the file.
The set.html page works as follows:
Contains a form with three fields, the filename, the field name, and the field value.
On submission, the form calls a CGI program that stores the pair at the end of the given filename.
If no filename currently exists in cgi-bin/ with the given name, a new one is created.
The new pair is added to the end of the file, this occurs even if an existing pair has the same name.
On success, the CGI program returns a blank page.
If something goes wrong and the new pair can't be written,
print out "ERROR," followed by a description of the problem.
Your can use any language you like, though if you want to use something besides C, Python or Perl you'll need to install it.
Here is a skeleton CGI program in C that shows how to obtain the query string and output a page.
It also has a couple helper functions for parsing out parameter values from the string.
Part 3.
Benchmark your CGI program using the Apache benchmark utility ab.
The utility is located in /usr/local/apache2/bin.
Type ab with no arguments to get a list of its features.
Complete this readme.txt file with the requests per second you measure using ab connecting locally to your server (that is using the base URL http://127.0.0.1).
I don't like having to sudo every time I edit something in /var/www. What can I do about that?
By default, apache runs the web server as the username www-data and the group www-data.
You can add yourself to this group and then modify the permissions of var/www:
sudo usermod -a -G www-data your-user-name
sudo chgrp -R www-data /var/www
sudo chmod -R g+w /var/www
sudo chmod ug+rw /var/www/*
Log out and then log back in
Submission.
I will be testing your application by logging into your sever, starting Apache and then going to the get and set pages.
You should also submit your CGI program source code, get.html, set.html and readme.txt to the Moodle dropbox.
The Moodle timestamp is the completion time for the assignment.