Running Your Own Apache Server

In this section of the class, we head in a new direction in which you will set up and run your own Apache HTTP server. You may never need to do this in "real life" -- if, for example, your IT department or hosting company takes care of such issues. However, it is a useful exercise to develop and broaden your understanding of Web servers. Even if you yourself are not in control of the Web server you use, you will find it useful to know about how it has been configured (and you may even have suggestions for configuration changes!).

In doing this exercise, there are some ground rules we need to follow when using the FAS computer systems:

ssh or telnet to ice.fas.harvard.edu
fas%  ssh ice

jharvard@ice's password: 

This example uses the fictitious user, jharvard -- your input and output will need to reflect your username. Also, ice.fas.harvard.edu is a group of machines -- you need to know the name of the machine you are logged into. In the case below, the user jharvard is logged into the machine is03.fas.harvard.edu.

ice%  whoami
jharvard

ice%  hostname
is03

Download Apache

Apache is freely available. You can download precompiled binaries for many platforms, or you can download the source code and compile it yourself.

We will download the binary for the platform Digital Unix. This is most easily accomplished through lynx. The relevant URLs on the Apache site are:

ice%  lynx -source \
?  http://www.apache.org/dist/binaries/digitalunix/apache_1.3.9-alpha-dec-osf.tar.gz \
?  > apache_1.3.9-alpha-dec-osf.tar.gz

ice%  ls -l ~/apache_1.3.9-alpha-dec-osf.tar.gz 
-rwx-----x   1 jharvard  student   2569782 Dec  2 11:10 /home/j/h/jharvard/apache_1.3.9-alpha-dec-osf.tar.gz

Unpack the distribution file

ice%  ls -l ~/apache_1.3.9-alpha-dec-osf.tar.gz 
-rwx-----x   1 jharvard  student   2569782 Dec  2 11:10 /home/j/h/jharvard/apache_1.3.9-alpha-dec-osf.tar.gz
ice%  tar zxvf apache_1.3.9-alpha-dec-osf.tar.gz 
apache_1.3.9/
apache_1.3.9/src/
apache_1.3.9/src/ap/
apache_1.3.9/src/ap/.indent.pro

....list of files extracted....
....truncated in this handout..
....for brevity................

apache_1.3.9/README.bindist
apache_1.3.9/INSTALL.bindist
apache_1.3.9/install-bindist.sh

Or, we could do it in two steps:

  1. gunzip to decompress the ".gz" file
  2. unpack the tar file
ice%  gunzip apache_1.3.9-alpha-dec-osf.tar.gz 
ice%  ls apache_1.3.9-alpha-dec-osf.tar
-rw-------   1 jharvard  student  10076160 Dec  6 18:34 apache_1.3.9-alpha-dec-osf.tar
ice%  tar xvf apache_1.3.9-alpha-dec-osf.tar 
apache_1.3.9/
apache_1.3.9/src/
apache_1.3.9/src/ap/
apache_1.3.9/src/ap/.indent.pro
....list of files extracted....
apache_1.3.9/README.bindist
apache_1.3.9/INSTALL.bindist
apache_1.3.9/install-bindist.sh

A look at the distribution files

ls ~/apache_1.3.9

ice%  cd apache_1.3.9

ice%  ls
ABOUT_APACHE     Makefile.tmpl     build.log       icons
Announcement     README            cgi-bin         install-bindist.sh
INSTALL          README.NT     conf            logs
INSTALL.bindist  README.bindist    config.layout   src
KEYS             README.configure  config.status
LICENSE          WARNING-NT.TXT    configure
Makefile     bindist           htdocs

cat README.bindist

ice%  cat README.bindist
 
Apache 1.3.9 binary distribution
================================
 
This binary distribution is usable on a "alpha-dec-osf"
system and was built by "rmorgan@bet.covalent.net".

The distribution contains all standard Apache modules as shared
objects. This allows you to enable or disable particular modules
with the LoadModule/AddModule directives in the configuration file
without the need to re-compile Apache.

See "INSTALL.bindist" on how to install the distribution.
 
NOTE: Please do not send support-related mails to the address mentioned
      above or to any member of the Apache Group! Support questions
      should be directed to the "comp.infosystems.www.servers.unix"
      or "comp.infosystems.www.servers.ms-windows" newsgroup
      (as appropriate for the platform you use), where some of the
      Apache team lurk, in the company of many other Apache gurus
      who should be able to help.
      If you think you found a bug in Apache or have a suggestion please
      visit the bug report page at http://www.apache.org/bug_report.html
 
----------------------------------------------------------------------
Server version: Apache/1.3.9 (Unix)
Server built:   Aug 16 1999 14:50:57
Server's Module Magic Number: 19990320:6
Server compiled with....
 -D HAVE_MMAP
 -D USE_MMAP_SCOREBOARD
 -D USE_MMAP_FILES
 -D USE_FLOCK_SERIALIZED_ACCEPT
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D HTTPD_ROOT="/usr/local/apache"
 -D SUEXEC_BIN="bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/httpd.scoreboard"
 -D DEFAULT_LOCKFILE="logs/httpd.lock"
 -D DEFAULT_XFERLOG="logs/access_log"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"
 -D ACCESS_CONFIG_FILE="conf/access.conf"
 -D RESOURCE_CONFIG_FILE="conf/srm.conf"
----------------------------------------------------------------------

cat INSTALL.bindist

ice%  cat INSTALL.bindist
 
Apache 1.3.9 binary installation
================================
 
To install this binary distribution you have to execute the installation
script "install-bindist.sh" in the top-level directory of the distribution.
 
The script takes the ServerRoot directory into which you want to install
Apache as an option. If you ommit the option the default path
"/usr/local/apache" is used.
Make sure you have write permissions in the target directory, e.g. switch
to user "root" before you execute the script.
 
See "README.bindist" for further details about this distribution.
 
Please note that this distribution includes the complete Apache source code.
Therefore you may compile Apache yourself at any time if you have a compiler
installation on your system.
See "INSTALL" for details on how to accomplish this.

Installing Apache

ice%  ./install-bindist.sh /home/j/h/jharvard/apache
Installing binary distribution for platform alpha-dec-osf
into directory /home/j/h/jharvard/apache ...
Ready.
 +--------------------------------------------------------+
 | You now have successfully installed the Apache 1.3.9   |
 | HTTP server. To verify that Apache actually works      |
 | correctly you should first check the (initially        |
 | created or preserved) configuration files:             |
 |                                                        |
 |   /home/j/h/jharvard/apache/conf/httpd.conf
 |                                                        |
 | You should then be able to immediately fire up         |
 | Apache the first time by running:                      |
 |                                                        |
 |   /home/j/h/jharvard/apache/bin/apachectl start 
 |                                                        |
 | Thanks for using Apache.       The Apache Group        |
 |                                http://www.apache.org/  |
 +--------------------------------------------------------+

What has been installed?

ice%  cd ~jharvard/apache/

ice%  ls
bin      conf     icons    libexec  man
cgi-bin  htdocs   include  logs     proxy

The conf directory

ice%  cd conf

ice%  ls
access.conf          magic               srm.conf
access.conf.default  magic.default       srm.conf.default
httpd.conf           mime.types
httpd.conf.default   mime.types.default

cp httpd.conf httpd.conf.original

ice%  cp httpd.conf httpd.conf.original

ice%  ls
access.conf          httpd.conf.original  mime.types.default
access.conf.default  magic                srm.conf
httpd.conf           magic.default         srm.conf.default
httpd.conf.default   mime.types

http.conf

httpd.conf Make a backup copy of the original httpd.conf file and then edit the httpd.conf file. Substitute your favorite text editor for "emacs" below (such as pico).
ice%  cp httpd.conf httpd.conf.original
ice%  emacs httpd.conf

What has changed?

ice%  diff httpd.conf httpd.conf.original
306c306
< Port 8080
---
> Port 80
320,321c320,321
< User jharvard
< Group student
---
> User nobody
> Group nobody
328c328
< ServerAdmin jharvard@fas.harvard.edu
---
> ServerAdmin you@your.address
831,836c831,836
< <Location /server-status>
<     SetHandler server-status
<     Order deny,allow
<     Deny from all
<     Allow from fas.harvard.edu
< </Location>
---
> #<Location /server-status>
> #    SetHandler server-status
> #    Order deny,allow
> #    Deny from all
> #    Allow from .your_domain.com
> #</Location>
843,848c843,848
< <Location /server-info>
<     SetHandler server-info
<     Order deny,allow
<     Deny from all
<     Allow from fas.harvard.edu
< </Location>
---
> #<Location /server-info>
> #    SetHandler server-info
> #    Order deny,allow
> #    Deny from all
> #    Allow from .your_domain.com
> #</Location>

The bin Directory

ice%  cd ../

ice%  ls
bin      conf     icons    libexec  man
cgi-bin  htdocs   include  logs     proxy

ice%  cd bin/

ice%  ls
ab          apxs        htdigest    httpd       rotatelogs
apachectl   dbmmanage   htpasswd    logresolve

Apachectl

ice%  ./apachectl
usage: ./apachectl (start|stop|restart|fullstatus|status|graceful|configtest|help)

start      - start httpd -d /home/j/h/jharvard/apache -R /home/j/h/jharvard/apache/libexec"
stop       - stop httpd -d /home/j/h/jharvard/apache -R /home/j/h/jharvard/apache/libexec"
restart    - restart httpd if running by sending a SIGHUP or start if 
             not running
fullstatus - dump a full status screen; requires lynx and mod_status enabled
status     - dump a short status screen; requires lynx and mod_status enabled
graceful   - do a graceful restart by sending a SIGUSR1 or start if not running
configtest - do a configuration syntax test
help       - this screen


./apachectl configtest

ice%  ./apachectl configtest
Syntax OK

Apachectl: start

ice%  ./apachectl start
./apachectl start: httpd started

Accessing our Web Server

ice%  hostname
is03


lynx -dump http://is03.fas.harvard.edu:8080/

ice%  lynx -dump http://is03.fas.harvard.edu:8080/

      It Worked! The Apache Web Server is Installed on this Web Site!
                                      
   If you can see this page, then the people who own this domain have
   just installed the [1]Apache Web server software successfully. They
   now have to add content to this directory and replace this placeholder
   page, or else point the server at their real content.
     _________________________________________________________________
   
     If you are seeing this page instead of the site you expected,
     please contact the administrator of the site involved. (Try sending
     mail to <Webmaster@domain>.) Although this site is running the
     Apache software it almost certainly has no other connection to the
     Apache Group, so please do not send mail about this site or its
     contents to the Apache authors. If you do, your message will be
     ignored.
     _________________________________________________________________
   
   The Apache [2]documentation has been included with this distribution.
   
   The Webmaster of this site is free to use the image below on an
   Apache-powered Web server. Thanks for using Apache!

References

   1. http://www.apache.org/
   2. http://is03.fas.harvard.edu:8080/manual/index.html

Server Status

ice%  lynx -dump http://is03.fas.harvard.edu:8080/server-status

                 Apache Server Status for is03.fas.harvard.edu
                                       
   Server Version: Apache/1.3.9 (Unix)
   Server Built: Aug 16 1999 14:50:57
     _________________________________________________________________
   
   Current Time: Thursday, 02-Dec-1999 11:26:42 EST
   Restart Time: Thursday, 02-Dec-1999 11:26:05 EST
   Parent Server Generation: 0
   Server uptime: 37 seconds
   1 requests currently being processed, 5 idle servers
W_____..........................................................
................................................................
................................................................
................................................................

   Scoreboard Key:
   "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
   "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
   "L" Logging, "G" Gracefully finishing, "." Open slot with no current
   process
   
   PID Key:
   7704 in state: W ,   3119 in state: _ ,   22386 in state: _ 
   13839 in state: _ ,   16414 in state: _ ,   25002 in state: _ 
     _________________________________________________________________
   
   To obtain a full report with current status information you need to
   use the ExtendedStatus On directive.
     _________________________________________________________________
   
   
    Apache/1.3.9 Server at is03.fas.harvard.edu Port 8080

lynx -dump http://is03.fas.harvard.edu:8080/server-info

ice%  lynx -dump http://is03.fas.harvard.edu:8080/server-info

                         Apache Server Information
                                      
   [1]Server Settings, [2]mod_setenvif.c, [3]mod_so.c,
   [4]mod_unique_id.c, [5]mod_usertrack.c, [6]mod_headers.c,
   [7]mod_expires.c, [8]mod_cern_meta.c, [9]mod_proxy.c,
   [10]mod_digest.c, [11]mod_auth_dbm.c, [12]mod_auth_anon.c,
   [13]mod_auth.c, [14]mod_access.c, [15]mod_rewrite.c, [16]mod_alias.c,
   [17]mod_userdir.c, [18]mod_speling.c, [19]mod_actions.c,
   [20]mod_imap.c, [21]mod_asis.c, [22]mod_cgi.c, [23]mod_dir.c,
   [24]mod_autoindex.c, [25]mod_include.c, [26]mod_info.c,
   [27]mod_status.c, [28]mod_negotiation.c, [29]mod_mime.c,
   [30]mod_mime_magic.c, [31]mod_log_config.c, [32]mod_env.c,
   [33]mod_vhost_alias.c, [34]http_core.c
     _________________________________________________________________
   
....rest of output truncated.....

A look at Processes and Logs

Processes

ice%  ps -u jharvard
   PID TTY      S           TIME CMD
  3119 ??       S        0:00.00 /home/j/h/jharvard/apache/bin/httpd -d /home/c/
  7704 ??       S        0:00.02 /home/j/h/jharvard/apache/bin/httpd -d /home/c/
 13839 ??       S        0:00.00 /home/j/h/jharvard/apache/bin/httpd -d /home/c/
 16414 ??       S        0:00.00 /home/j/h/jharvard/apache/bin/httpd -d /home/c/
 22386 ??       S        0:00.00 /home/j/h/jharvard/apache/bin/httpd -d /home/c/
 22942 ??       S        0:00.07 /home/j/h/jharvard/apache/bin/httpd -d /home/c/
 25002 ??       S        0:00.00 /home/j/h/jharvard/apache/bin/httpd -d /home/c/
 15204 ttyp6    S        0:00.14 -h -is (tcsh)
 10081 ttyrb    I        0:00.17 -tcsh (tcsh)

Server logs

ice%  cd ../logs

ice%  ls

access_log  error_log  httpd.pid

ice%  cat access_log 
is03.fas.harvard.edu - - [02/Dec/1999:11:26:42 -0500] "GET /server-status HTTP/1.0" 200 1544
140.247.30.103 - - [02/Dec/1999:11:26:48 -0500] "GET / HTTP/1.0" 200 1622
is03.fas.harvard.edu - - [02/Dec/1999:11:26:56 -0500] "GET /server-info HTTP/1.0" 200 45662

ice%  cat error_log 
[Thu Dec  2 11:26:08 1999] [notice] Apache/1.3.9 (Unix) configured -- resuming normal operations
[Thu Dec  2 11:27:19 1999] [notice] caught SIGTERM, shutting down

Stopping Apache

ice%  ls
ab          apxs        htdigest    httpd       rotatelogs
apachectl   dbmmanage   htpasswd    logresolve

./apachectl stop

ice%  ./apachectl stop
./apachectl stop: httpd stopped

Processes

ice%  ps -u jharvard
   PID TTY      S           TIME CMD
 15204 ttyp6    S        0:00.15 -h -is (tcsh)
 10081 ttyrb    I        0:00.17 -tcsh (tcsh)
 12419 ttyrb    S  +     0:00.09 script
 12973 ttyrb    S  +     0:00.04 script