Running a private copy of Apache—or any copy of Apache!—is quite a bit more involved than running a copy of a simple web container such as Tomcat or Resin. The following is what I've been able to piece together so far from various documents.
Set an environment variable to point to the location of the Apache 2.2 distribution, as follows
setenv APACHE2_HOME /www/htdocs/CIS/software/apache2
Create an apache subdirectory under your home directory as follows
mkdir -p ${HOME}/apache2
and point APACHE_BASE to this directory
setenv APACHE2_HOME ${HOME}/apache2
Note that unlike with Tomcat, where the software "knows about" HOME and BASE, that is not the case with Apache—we are defining those environment variable only for our own convenience. We have to hand code those locations in many places in the httpd.conf file (shown below).
You will need to create an httpd.conf file under $APACHE_BASE, i.e. in your own personal space.
To start, copy the example file:
cp ${APACHE_HOME}/conf/original/httpd.conf ${APACHE_BASE}
Do a global search and replace, changing:
/www/htdocs/CIS/software/apache2
to
/home/usrk/f3/66143/apache2
Making this change will automatically make many of the changes that follow, but not all! So check each one carefully. This will also help you learn about how Apache works.
Find the ServerRoot and make sure it is the location of your APACHE_BASE. Note that as far as I know (and I could be wrong) you cannot use the Unix environment variable in this file. Apache has its own notion of environment variables, which differs from that of the Unix shell.
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to point the LockFile directive
# at a local disk. If you wish to share the same ServerRoot for multiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "/home/usrk/f3/66143/apache2"
Change to a port that is free. To find a free port, use the netstat command, for example to see if port 2222 is free, type the following at the Unix command line:
netstat -an | grep 22222
If port 2222 is free, use:
Listen 22222
Since you aren't root, you don't have permission to change user or change group. So just comment these out.
Change the ServerAdmin to your email address.
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
# ServerAdmin jsample@udel.edu
Change this to the directory where your documents will be located. Note that you probably cannot use ~jsample for your home directory—instead, you should spell out the exact location on the disk (/home/usrk/f3/66143/apache2/www/htdocs) not ~jsample/www/htdocs)
DocumentRoot "/home/usrk/f3/66143/apache2/htdocs"
Be sure you create this directory:
mkdir -p ${APACHE_BASE}/htdocs
Then also find this comment, and the Directory directive that follows,and change it to the same path:
# This should be changed to whatever you set DocumentRoot to. # <Directory "/home/usrk/f3/66143/apache2/htdocs">
Change the Port directive
Change to a port that is free. To find a free port, use the netstat command, for example to see if port 2222 is free, type the following at the Unix command line:
netstat -an | grep 22222
After finding a free port, change port 80 to that port. To be safe, choose a port value between 10000 and 65535.
# Port: The port to which the standalone server listens. For # ports < 1023, you will need httpd to be run as root initially. # Port 22222
Change the ServerAdmin to your email address.
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents.
#
ServerAdmin jsample@udel.edu
Change this to the directory where your documents will be located. Note that you probably cannot use ~jsample for your home directory—instead, you should spell out the exact location on the disk (/home/usrk/f3/66143/apache2/www/htdocs) not ~jsample/www/htdocs)
DocumentRoot "/home/usrk/f3/66143/apache2/www/htdocs"
Also find the following, and change it to the same directory:
# This should be changed to whatever you set DocumentRoot to. # <Directory "/home/usrk/f3/66143/apache2/www/htdocs">
Find the place in the file that looks like this:
<IfModule mime_module> # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig conf/mime.types
Change the directory to point to conf/mime.types under the original ${APACHE2_HOME}, as follows:
<IfModule mime_module> # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig /www/htdocs/CIS/software/apache2/conf/mime.types
Add the LockFile, PidFile and ScoreBoard directives
It turns out that if you read that comment above, and follow the link to http://www.apache.org/docs/mod/core.html#lockfile you discover that while the other files (configuration, error, and log) can be placed on an NFS mounted directory (such as your home directory) with no trouble, the lockfile cannot be placed there.
Also, unfortunately, on strauss, as far as I know, the only non-NFS mounted directory to which normal users have permission to write is /var/tmp. This creates its own problems, as the apache documentation points out:
"It is best to avoid putting this file in a world writable directory such as /var/tmp
because someone could create a denial of service attack and prevent the server from starting by creating a lockfile with the same name as the one the server will try to create."
However, unless someone can come up with a better solution, this is a vulnerability we have to live with. (In any case, if some malicious person does this to you, you can just change the name of your lockfile and get around the problem.)
So, make the following changes, substituting YOUR userid in place of jsample.
# The LockFile directive sets the path to the lockfile used when Apache
# is compiled with either USE_FCNTL_SERIALIZED_ACCEPT or
# USE_FLOCK_SERIALIZED_ACCEPT. This directive should normally be left at
# its default value. The main reason for changing it is if the logs
# directory is NFS mounted, since the lockfile MUST BE STORED ON A LOCAL
# DISK. The PID of the main server process is automatically appended to
# the filename.
#
LockFile /var/tmp/jsample.httpd.lock
# PidFile: The file in which the server should record its process
# identification number when it starts.
#
PidFile /var/tmp/jsample.httpd.pid
# ScoreBoardFile: File used to store internal server process information.
# Not all architectures require this. But if yours does (you'll know because
# this file will be created when you run Apache) then you *must* ensure that
# no two invocations of Apache share the same scoreboard file.
#
ScoreBoardFile /var/tmp/jsample.httpd.scoreboard
You should have the following section in your file (from doing the global search and replace earlier). Be sure it refers to your home directory for the cgi-bin directory,
... ScriptAlias /cgi-bin/ "/home/usra/d9/55560/apache2/cgi-bin/" </IfModule> <IfModule cgid_module> # # ScriptSock: On threaded servers, designate the path to the UNIX # socket used to communicate with the CGI daemon of mod_cgid. # #Scriptsock logs/cgisock </IfModule> # # "/home/usra/d9/55560/apache2/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "/home/usra/d9/55560/apache2/cgi-bin"> AllowOverride None ...
Also be sure you make that directory with
mkdir -p ${APACHE2_HOME}/apache2/cgi-bin
To check the syntax, run the httpd server with the -f and -t flags as shown below. This will parse your httpd.conf file to check for syntax errors, without actually starting up the server:
/usr/apache/bin/httpd -f ${APACHE_BASE}/httpd.conf -t
You should get output like the following:
> /usr/apache/bin/httpd -f ~/apache/httpd.conf -t Syntax OK >
To start the server for real, just drop the -t flag
> /usr/apache/bin/httpd -f ~/apache/httpd.conf >
To stop the server for real, use the kill command on the process id (which you can find in the /var/tmp/jsample.httpd.pid file, or by doing
ps -fu jsample
where jsample is your userid:
> kill 26539 >