Notes for Week 2

  1. On our systems, the following commands will install Apache:
    mount -wo remount /
    cd /usr/src
    tar -xjf httpd-2.0.49.tar.bz2
    cd httpd-2.0.49
    
    groupadd apache &&
    useradd -c apache -d /dev/null -g apache -s /bin/false apache
    
    patch -Np1 -i ../httpd-2.0.49-config.patch
    
    ./configure --with-expat=/usr --enable-ssl --enable-layout=LFS \
                --enable-mods-shared=all &&
    make &&
    make install
    
    sed -i -e "s%User nobody%User apache%" -e "s%^Group #-1%Group apache%" /etc/apache/httpd.conf
    
    cat > /etc/rc.d/init.d/apache << "EOF"
    #!/bin/sh
    . /etc/sysconfig/rc
    . $rc_functions
    case "$1" in
            start)
                    logecho "Starting Apache daemon..."
                    /usr/sbin/apachectl -k start
                    evaluate_retval
                    ;;
            stop)
                    logecho "Stopping Apache daemon..."
                    /usr/sbin/apachectl -k stop
                    evaluate_retval
                    ;;
            restart)
                    logecho "Restarting Apache daemon..."
                    /usr/sbin/apachectl -k restart
                    evaluate_retval
                    ;;
            status)
                    statusproc /usr/sbin/httpd
                    ;;
            *)
                    echo "Usage: $0 {start|stop|restart|status}"
                    exit 1
                    ;;
    esac
    EOF
    chmod 754 /etc/rc.d/init.d/apache
    
    mount -ro remount /
    
    The mount commands are necessary because our systems run with a read-only root filesystem (which is where we will be installing Apache). The build takes place in /usr/src/httpd-2.0.49 (the Apache source tree after it is uncompressed by tar), and the install is to directories in the /usr directory tree.

    This configuration is based on Beyond Linux From Scratch 5.1, and causes Apache to run its slave processes under the unprivileged user "apache". The "expat" parameter to configure tells Apache to use the version of expat (a C library for parsing XML) which is already installed. The file /etc/rc.d/init.d/apache is the script used to start and stop Apache.

  2. EXERCISES for Week 2:

    1. Start Apache using the command "/etc/rc.d/init.d/apache start". Observe from "ps aux" output that the actual server program is httpd: the HyperText Transfer Protocol Daemon. Note that the master process runs as root; it directs client requests to the slave processes. Test Apache by entering "127.0.0.1" as the URL in mozilla.
    2. The document root for your server is /var/www/htdocs. Create a home page for your server to replace the current index.html file. Reload the URL 127.0.0.1 to test your new home page.
    3. Using the information in last week's notes, add a firewall rule to permit access to your web server from other PCs in the lab. Re-run your firewall script and test access to your server from other stations.
    4. Stop Apache using the command "/etc/rc.d/init.d/apache stop". Examine the files in /var/log/apache.

      The access_log file contains the following information for every file served to a client:

      • the client IP address
      • the date and time of the request
      • the method (typically GET or POST)
      • the file name requested by the client
      • the HTTP version used by the client
      • the result code for the request
      • the number of bytes in the file


©2005, Kenneth R. Koehler. All Rights Reserved. This document may be freely reproduced provided that this copyright notice is included.

Please send comments or suggestions to the author.