<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>RunningYourOwnApache</title><revhistory><revision><revnumber>5</revnumber><date>2013-01-14 07:25:26</date><authorinitials>ClintonEbadi</authorinitials><revremark>cat</revremark></revision><revision><revnumber>4</revnumber><date>2008-07-07 04:28:03</date><authorinitials>localhost</authorinitials><revremark>converted to 1.6 markup</revremark></revision><revision><revnumber>3</revnumber><date>2008-06-08 14:43:42</date><authorinitials>BenjaminHell</authorinitials><revremark>Added startup script and appropriate cron jobs with k5start (and minor other things)</revremark></revision><revision><revnumber>2</revnumber><date>2008-05-25 13:31:08</date><authorinitials>AdamChlipala</authorinitials><revremark>Fix port request description</revremark></revision><revision><revnumber>1</revnumber><date>2008-05-24 11:22:50</date><authorinitials>BenjaminHell</authorinitials></revision></revhistory></articleinfo><para>This page describes how to run your own apache HTTP daemon, for example if you have special needs regarding apache modules etc. </para><para>In the following example an individual apache setup with <ulink url="http://www.modpython.org/">mod_python</ulink> is described (as <ulink url="https://wiki.hcoop.net/RunningYourOwnApache/BenjaminHell#">BenjaminHell</ulink> does it for <ulink url="http://www.siebengang.net/"/>). </para><section><title>Apache setup and startup</title><para>Get a working apache/mod_python installation (in your home dir), and set up a startup procedure, so that cron starts your daemon when mire reboots. In case the webserver process should crash, apache should be started again, too. The following shell script checks if apache is running and starts it if not (adjust the environment variables in the beginning accordingly): </para><screen><![CDATA[HOME=/afs/hcoop.net/user/...path to your home dir... # Adjust this!!!
SERVERROOT=$HOME/apache2 # The server root directory
PIDFILE=$SERVERROOT/logs/httpd.pid # Process PID gets stored here
HTTPD=$SERVERROOT/bin/httpd # The httpd executable
K5START="k5start -qtU -f /etc/keytabs/user.daemon/USER" # Adjust this!!!
]]><![CDATA[
# This is needed for mod_python
export PYTHONPATH="/afs/hcoop.net/user/b/be/beni/python"
]]><![CDATA[
if (test -f $PIDFILE); then
#if ($K5START -- test `ls $PIDFILE`); then
    PID=`cat $PIDFILE 2> /dev/null`
    kill -0 $PID 2> /dev/null
    if (test $? -ne 0); then
        $K5START -b -- $HTTPD -d $SERVERROOT -DFOREGROUND
    else
        exit 0
    fi
else
    $K5START -b -- $HTTPD -d $SERVERROOT -DFOREGROUND
fi
]]><![CDATA[
exit 0]]></screen><para>Save the script in a place like <code>$HOME/bin</code> and use cron to execute this script after reboots and every now and then to check if apache is still up and running (adjust capitalized parts): </para><screen><![CDATA[@reboot               k5start -qtU -f /etc/keytabs/user.daemon/USER -- PATH_TO_SCRIPT
0-59/5 *   *   *   *  k5start -qtU -f /etc/keytabs/user.daemon/USER -- PATH_TO_SCRIPT]]></screen><section><title>Port issues</title><para>Your httpd must be configured so that it listens on a dedicated port.  The standard port 80 won't work. We use a firewall to keep track of which ports members are using. Submit a firewall rule request on <ulink url="https://members.hcoop.net/portal/sec">the portal's security settings page</ulink> to get ProxiedServer ports. </para><para>Put a line like this into <code>httpd.conf</code> to configure apache so that it listens on this port only: </para><screen><![CDATA[Listen 8880 # Whatever port number you got]]></screen></section><section><title>mod_python specials</title><para>Apache needs to know where in the Python path to look for mod_python. You need to add the mod_python location to your <ulink url="https://wiki.hcoop.net/RunningYourOwnApache/PythonPath#">PythonPath</ulink> in <code>httpd.conf</code>: </para><screen><![CDATA[<IfModule mod_python.c>
    PythonPath "sys.path + ['/afs/hcoop.net/WHEREVER_MOD_PYTHON_IS_INSTALLED']"
</IfModule]]></screen></section></section><section><title>domtool config</title><para>Next you need &quot;port forwarding&quot; of http requests for your domain to your own httpd (so that you don't need to use addresses like <ulink url="http://www.siebengang.net:8880/index.html"/>, but <ulink url="http://www.siebengang.net/index.html"/> gets &quot;mapped&quot; to port 8880). In the domtool setup for <ulink url="http://www.siebengang.net/"/> this looks like </para><screen><![CDATA[domain "siebengang.net" with
  (* NS/DNS/Mail stuff omitted *)
  web "www" with
    proxyPass "/" "http://bog:8880/";
    proxyPassReverse "/" "http://bog:8880/";
  end;
end;]]></screen><para>That should be about all you need... </para></section><section><title>Possible AFS problems</title><para>In our AFS environment apache has to be started through k5start to get the right file permissions. However, as a default, httpd detaches from its parent process after the completed startup. This would make it impossible for k5start to renew AFS tickets for the process. The <code>-DFOREGROUND</code> option prevents apache from doing so, and with <code>-b</code> k5start can take care of the backgrounding instead. </para><para>If you do not consider this, you may run into &quot;permission denied&quot; problems (see Bugzilla <ulink url="https://bugzilla.hcoop.net/show_bug.cgi?id=291">bug 291</ulink>). </para><!--rule (<hr>) is not applicable to DocBook--><para> <ulink url="https://wiki.hcoop.net/RunningYourOwnApache/CategoryMemberManual#">CategoryMemberManual</ulink> </para></section></article>