|
CSCI A348/548
|
You may already have a web server, installed following the notes from the first lecture, with a welcome page. We have installed the web server, made the necessary changes to the configuration files and started the web server. Today we want to revisit installation and configuration of Apache because we want to make sure all is very clear. We also review the issues related to starting and stopping the server and introduce a way to start the server automatically (if necessary) to protect it from system reboots. This also counts as a Unix review, to a certain extent.
1. Announcements
You are encouraged to work on assignments together, you'll get to know each other so that you can work on the projects in teams. Also make sure you know of and make good use of the class newsgroup, located at: ac.csci.a348
Apache should be installed in your directory and the relevant directory structure should be like this:
/u/username/httpd/ # directory
/u/username/httpd/httpd # file
/conf/ # directory
/conf/httpd.conf # file
/srm.conf # file
/access_conf # file
/htdocs/ # directory
/htdocs/index.html # file
/cgi-bin/ # directory
/logs/ # directory
/logs/access_log # file
/logs/error_log # file
/logs/httpd.pid # file
Apache descends from NCSA and CERN so the structure is similar. Here's a quick description of these files and directories.
/u/username/httpd/
This is the ServerRoot directory.
/u/username/httpd/httpd This file is the actual web server. You need to restart your server every time you make a change to one of your configuration files.
/u/username/httpd/conf/ This directory contains configuration files.
/u/username/httpd/conf/httpd.conf This is the server's main configuration file.
/u/username/httpd/conf/srm.conf This is the server resource configuration file.
/u/username/httpd/conf/access_conf This is the global access control file.
/u/username/httpd/htdocs/
This is the DocumentRoot directory.
/u/username/httpd/htdocs/index.html This is the server's welcome page.
/u/username/httpd/cgi-bin/ This is the CGI scripts directory.
/u/username/httpd/logs/ This directory contains log files.
/u/username/httpd/logs/access_log The accesses to your site are logged here.
/u/username/httpd/logs/error_log The server logs here any errors that hit has to report.
/u/username/httpd/logs/httpd.pid This file contains the process id of the server.3. Configuration of Apache
httpd.conf
In what follows please use your username instead of dgerman, and your port number for
10000. The file below is the one for the following assignment:
dgerman
10000
burrowww.cs.indiana.edu% diff httpd.conf httpd.conf-dist 32c32 < Port 10000 --- > Port 80 52c52 < User dgerman --- > User nobody 58c58 < ServerAdmin dgerman@indiana.edu --- > ServerAdmin you@your.address 66c66 < ServerRoot /u/dgerman/httpd --- > ServerRoot @@ServerRoot@@ 127c127 < LockFile /tmp/apache.lockfile.dgerman --- > #LockFile logs/accept.lock 185,186c185,186 < MinSpareServers 1 < MaxSpareServers 3 --- > MinSpareServers 5 > MaxSpareServers 10 190c190 < StartServers 1 --- > StartServers 5 burrowww.cs.indiana.edu%
So we change:
Port
User
ServerAdmin
ServerRoot
LockFile
MinSpareServersMaxSpareServers
StartServers
srm.conf
Please use your username instead of dgerman.
So we change:burrowww.cs.indiana.edu% diff srm.conf srm.conf-dist 15c15 < DocumentRoot /u/dgerman/httpd/htdocs --- > DocumentRoot @@ServerRoot@@/htdocs 20c20 < UserDir httpd/htdocs --- > UserDir public_html 143c143 < Alias /icons/ /u/dgerman/httpd/icons/ --- > Alias /icons/ @@ServerRoot@@/icons/ 148c148 < ScriptAlias /cgi-bin/ /u/dgerman/httpd/cgi-bin/ --- > #ScriptAlias /cgi-bin/ @@ServerRoot@@/cgi-bin/ burrowww.cs.indiana.edu%
DocumentRoot
UserDir
Alias /icons/
ScriptAlias /cgi-bin/
access.conf Please use your username instead of dgerman.
So we change two pathnames for:burrowww.cs.indiana.edu% diff access.conf access.conf-dist 28c28 < <Directory /u/dgerman/httpd/htdocs> --- > <Directory @@ServerRoot@@/htdocs> 54c54 < <Directory /u/dgerman/httpd/cgi-bin> --- > <Directory @@ServerRoot@@/cgi-bin> burrowww.cs.indiana.edu%
cgi-bin directory.
If your server is not running already you need to login
into burrowww and type the following command:
where you need to replace/u/dgerman/httpd/httpd -d /u/dgerman/httpd
dgerman with your username.
If your server is already running you won't be able to start the server with the command above. See restarting the server below.
To check if your server is running or not use:
where username is your username. This should also return the server's/usr/bin/ps -ef | grep httpd | grep username
pid.
5. Stopping the server
This can be done with:
Make sure you notice the backquotes (kill -TERM `cat /u/username/httpd/logs/httpd.pid`
`) above. If the file does not exist you should find the pid of the server (as described before) and use
where pid is the process id, that is, a(n up to 5-digit) number.kill -TERM pid
6. Restarting the server
Same considerations apply.kill -HUP `cat /u/username/httpd/logs/httpd.pid`
8. Log files
Significant events, such as starting, stopping, restarting, and errors in general are recorded in
@@ServerRoot@@/logs/error.log
This file is useful for debugging CGI scripts and monitoring the server
in general.
@@ServerRoot@@/logs/access.log contains a log of all calls
to your server.
7. Protecting the server from machine reboots
Use starthttpd (written by Steve Kinzler) to start and stop the server.
Copy it into your bin directory:
(Replace username with your username but do copy it from my account).cp /u/dgerman/bin/starthttpd /u/username/bin/starthttpd-template cp /u/username/bin/starthttpd-template /u/username/bin/starthttpd
Then use the editor of your choice to change the script for your account such that the differences are like this:
Use crontab to schedule starthttpd.burrowww.cs.indiana.edu% diff starthttpd starthttpd-template 11c11 < basecmd="/u/dgerman/httpd/httpd -d $httpd" --- > basecmd="/u/username/httpd/httpd -d $httpd" burrowww.cs.indiana.edu%
This starts the server (if necessary) every day at 6am.burrowww.cs.indiana.edu% crontab -e burrowww.cs.indiana.edu% crontab -l 0 6 * * * /u/dgerman/bin/starthttpd burrowww.cs.indiana.edu%
#!/usr/bin/perl
open(AB, $ARGV[0]);
while ($x = <AB>) {
print "Read: ", $x;
($uname, $pword) = split(/:/, $x);
chop($pword);
$pairs{$uname} = $pword;
}
close(AB);
@m = keys %pairs;
foreach $k (@m) {
print $k, "\n";
}
while ($user = <STDIN>) {
chop($user);
if ($user =~ /^quit$/i) { exit; }
print "(", $user, ")\n";
if ($pairs{$user}) {
print "Yes, ", $user, " appears in the list.\n";
} else {
print "No, I don't see ", $user, "\n";
}
}
A348/A548.