You will learn to manage an Ubuntu server in "the cloud".
You will be installing your own Apache web server.
You will be learning to create and benchmark a dynamic web application using CGI.
Part 1: Setting up your server
You will be creating your own 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, Apache and PHP.
Each student has their very own virtual machine (VM) thanks to the fine folks at MERDI.
Each VM has a public IP address which you can use to login at using the credentials you were given.
The servers are running SSH on a non-default port, so you'll need to use the -p flag to the ssh command.
The wireless network may block this port, so you may need to login in via a wired campus connection or by going through katie.
I will be changing the password on the initial account you were given. I will use this account to login and check your assignments.
You should thus create your own user account on the VM. Use the same username as your Montana Tech username.
Be sure to add yourself to sudoers so you can sudo.
sudo adduser <mtech username>
NOTE: select a secure password! Despite SSH running on a non-standard port, you can expect bot attacks on your SSH server.
sudo /usr/sbin/visudo
Create a new user privilege specification for your username, copying the format of the existing root user.
Logout out of the server. Login with your newly created account. Verify you can sudo with your new account.
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.
Test out the web server:
Open a browser to the IP address of your server. You should see Apache's default "It works!" web page.
Practice starting/stopping/restarting your web server using sudo /etc/init.d/apache2
Test making a change to the default main web site page located at /var/www
Familiarize yourself with Apache's logging:
Log files live in /var/log/apache2
You need to enable CGI (Common Gateway Interface) as it is not enabled by default in Apache.
Tell Apache to load the CGI module by adding a symlink in the /etc/apache2/mods-enabled directory to the /etc/apache2/mods-available/cgi.load file. You can do this using the ln -s source dest command.
Restart Apache so the change takes effect.
By default, web requests to http://X.X.X.X/cgi-bin look for a script or program in /usr/lib/cgi-bin. This is where you need to put your CGI program.
Here is a simple Bash script that you can use for testing that just returns a simple message:
#!/bin/bash
echo "Content-type: text/plain;charset=iso-8859-1"
echo
echo
echo "Hello from my script!"
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: Benchmarking CGI
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 GET parameter fields (named exactly as follows):
file, the filename
name, 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 (named exactly as follows):
file, the filename
name, the field name
value, 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.
You can use any language you like, though you may need to install a compiler/interpreter for your chosen language.
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.
You will need to install the package apache2-utils to get this utility.
To eliminate other sources of performance issues, we'll first benchmark locally on your server.
You will also benchmark in a more realistic situation, from another server of your own choosing (e.g. katie).
Type ab with no arguments to get a list of its features.
Complete this readme.txt file with the requests per second you measured using ab.
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.