Apache installation. Unix commands. HTML.

We all know what a web server does.

We have seen web servers, we have interacted with them (via browsers).

Now we're going to install one (of the most popular web servers ever).

What is our model about that? What do we expect?

1. Your Unix Account

We created Unix accounts on silo for everybody.

You use ssh to connect to your account.

Once connected, you type Unix commands to accomplish tasks.

We look at what we do, and mention the commands we have to issue, below.

2. Installation of Apache (Part One).

Once Apache is installed we get the following hierarchy of folders:

In the diagram above the flat (regular) files have been underlined.

The other names in the diagram denote folders.

The diagram is restricted to the very essential:

That's what we get through installation.

Now let's explain how we obtain it, that is, how we get it done.

3. Installation of Apache. (Part Two).

You basically got a brand new account, logged in and typed the following:

  1. makenobackup
    This command creates a no backup folder with your username, workspace.
  2. cd /nobackup/[username]
    We moved there.
  3. cp /l/www/classes/a348/sum2006/software/httpd-2.2.2.tar.gz .
    Get the archive (notice the dot; how else could we have written this?)
  4. gunzip httpd-2.2.2.tar.gz
    Unzipped the archive. Use ls -l to see the increase in size, loss of .gz extension.
  5. tar xvf httpd-2.2.2.tar
    Extract the archive. This creates a folder.
  6. cd httpd-2.2.2
    Move into that folder.
  7. ./configure --prefix=/u/[username]/apache --enable-so
    Use the configure utility provided to create a make file for this installation.
  8. make
    Compile everything.
  9. make install
    Place every compiled file, etc. into its final, installation position.
  10. cd ~/apache/conf
    Move into the configuration folder of the apache installation.
  11. pico httpd.conf
    Get ready to change two lines in the file before starting the server.
  12. change Listen 80 to Listen [port]
    By [port] I mean 16206 or whatever actual number was assigned to you.
  13. Change User daemon into User [username]
    By [username] just like above I mean your actual username.
  14. Exit pico, then start your server.
    Use ~/apache/bin/apachectl start to start your server.
  15. Access your server at the address listed on the students page.
    The url is http://silo.cs.indiana.edu:[port] (where [port] is your port number).
  16. Go into ~/apache/htdocs and edit your index.html file.
    You can use pico ~/apache/htdocs/index.html to access it regardless of your location.

4. Unix.

Use ls, ls -l to list files in a directory.

The current folder is represented by a dot (.) like in the copy above.

The parent folder is represented by two dots (..) next to each other.

Use cd to change the current directory.

Use pwd to see what your current directory is.

Use cp to copy a file from one place to another.

Use the IU Knowledge Base (kb.iu.edu) to read more about Unix commands.

The ~ symbol is shortcut for /u/[username] where [username] is your actual username.

The cd ~ command then is equivalent with cd /u/[username] (but also with just cd, with no argument).

The three files in ~/apache/logs are:

You can use tail file, tail -[number] file, or tail -f file to look at the last part of a file.

You can use cat, more to see the contents of a file.

5. HTML

HTML is a markup language.

You write HTML tags in a file to indicate how the contents should be rendered.

The server sends the file to the browser, by request, and the browser renders it.

We only want to create a simple page that identifies you (text, one picture).

Here's my demo page (located in ~/apache/htdocs/index.html):

<html>
  <body>
    <h1>It works!</h1>

    <p>This server belongs to Adrian German</p>

    <img src="http://weblogs.newsday.com/sports/basketball/knicks/blog/home/tiblogs/public_html/sports/basketball/knicks/blog/bird.jpg">

  </body>
</html>
Our programs will print HTML.

Their user interfaces are encoded in HTML too.

6. A Simple CGI Script.

Now that we saw what a simple HTML file looks like, let's see a simple CGI script.

We start with CGI scripts written in Perl.

Programs in Perl need to start with a line like this:

#!/usr/bin/perl
The rest of the file is the actual program in Perl.

The first line indicates the location of the perl interpreter.

To create a Perl program you can use pico, to create the file with the contents you want.

The file we created looked like this:

#!/usr/bin/perl

use CGI;                                    # import a class (module) 

$q = new CGI;                               # create an object of that type 

print $q->header, $q->start_html;           # use the object to print important HTTP and HTML code 

print "How are you? <p>";                   # print statement, prints a string

$a = localtime;                             # localtime procedure is invoked, value returned is stored in variable a

print $a;                                   # names of variables start with $, @, % in Perl (type information) 

print $q->end_html;                         # use the CGI object to end the HTML code in the printed page 
This program reports the time on the server.

The file needs to be made executable before it can run.

If the file name is one, you type chmod 700 one (or chmod +x one) to make it executable.

You can also run web scripts from the command line (use ./one if you're in the same directory).

Another way to debug scripts is to look in ~/apache/logs/error_log for error messages.

Next week we introduce Perl and Python and use them to write CGI scripts that keep state.