Okay, the server setup procedure I used is as follows:
a) FreeBSD 8.1 (AMD64/x64 architecture) with minimal install, with the following additional software/features from the install DVD:
1) bash
2) curl
3) perl
4) FreeBSD Ports collection in /usr/ports
b) Disabled sendmail with the following additions to /etc/rc.conf:
sendmail_enable="NONE"
sendmail_msp_queue_enable="NO"
sendmail_outbound_enable="NO"
sendmail_submit_enable="NO"
c) Install Hiawatha...
bsd# cd /usr/ports/www/hiawatha/
bsd# make
[Selection for Hiawatha build: All, except Hiawatha CommandChannel and IPv6 support - the default included IPv6, but I unticked that item only]
[Selection for libxslt build: All, except Enable Memory Debugging - the default selection, in fact]
Lots and lots of compiling, and then installation:
bsd# make install
===> Installing for hiawatha-7.3
===> hiawatha-7.3 depends on executable: pkg-config - found
===> hiawatha-7.3 depends on shared library: xml2.5 - found
===> hiawatha-7.3 depends on shared library: xslt.2 - found
===> Generating temporary packing list
===> Checking if www/hiawatha already installed
test -z "/usr/local/bin" || ./install-sh -c -d "/usr/local/bin"
install -s -o root -g wheel -m 555 'ssi-cgi' '/usr/local/bin/ssi-cgi'
test -z "/usr/local/sbin" || ./install-sh -c -d "/usr/local/sbin"
install -s -o root -g wheel -m 555 'cgi-wrapper' '/usr/local/sbin/cgi-wrapper'
install -s -o root -g wheel -m 555 'hiawatha' '/usr/local/sbin/hiawatha'
install -s -o root -g wheel -m 555 'php-fcgi' '/usr/local/sbin/php-fcgi'
install -s -o root -g wheel -m 555 'wigwam' '/usr/local/sbin/wigwam'
test -z "/usr/local/sbin" || ./install-sh -c -d "/usr/local/sbin"
install -o root -g wheel -m 555 'extra/newroot' '/usr/local/sbin/newroot'
make install-exec-hook
chmod u+s /usr/local/sbin/`echo cgi-wrapper | sed -e "s,x,x,"`
test -z "/var/log/hiawatha" || ./install-sh -c -d "/var/log/hiawatha"
test -z "/usr/local/man/man1" || ./install-sh -c -d "/usr/local/man/man1"
install -o root -g wheel -m 444 './doc/cgi-wrapper.1' '/usr/local/man/man1/cgi-wrapper.1'
install -o root -g wheel -m 444 './doc/hiawatha.1' '/usr/local/man/man1/hiawatha.1'
install -o root -g wheel -m 444 './doc/newroot.1' '/usr/local/man/man1/newroot.1'
install -o root -g wheel -m 444 './doc/php-fcgi.1' '/usr/local/man/man1/php-fcgi.1'
install -o root -g wheel -m 444 './doc/ssi-cgi.1' '/usr/local/man/man1/ssi-cgi.1'
install -o root -g wheel -m 444 './doc/wigwam.1' '/usr/local/man/man1/wigwam.1'
test -z "/usr/local/www/hiawatha" || ./install-sh -c -d "/usr/local/www/hiawatha"
install -o root -g wheel -m 444 'doc/index.html' '/usr/local/www/hiawatha/index.html'
make install-data-hook
===============================================================================
The Hiawatha webserver is now installed.
Edit the configuration files in /usr/local/etc/hiawatha to suit your needs.
Add hiawatha_enable="YES" to rc.conf and start Hiawatha by running:
/usr/local/etc/rc.d/hiawatha start
===============================================================================
===> Installing rc.d startup script(s)
===> Compressing manual pages for hiawatha-7.3
===> Registering installation for hiawatha-7.3
===> SECURITY REPORT:
This port has installed the following binaries which execute with
increased privileges.
/usr/local/sbin/cgi-wrapper
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/sbin/hiawatha
This port has installed the following startup scripts which may cause
these network services to be started at boot time.
/usr/local/etc/rc.d/hiawatha
If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type 'make deinstall'
to deinstall the port if this is a concern.
For more information, and contact details about the security
status of this software, see the following webpage:
http://www.hiawatha-webserver.org/
d) Set it up so that it actually runs at startup:
bsd# echo 'hiawatha_enable="YES"' >>/etc/rc.conf
bsd# cat /etc/rc.conf
# -- sysinstall generated deltas -- # Tue Oct 12 17:13:34 2010
# Created: Tue Oct 12 17:13:34 2010
# Enable network daemons for user convenience.
# Please make all changes to this file, not to /etc/defaults/rc.conf.
# This file now contains just the overrides from /etc/defaults/rc.conf.
hostname="bsd.speedport.ip"
ifconfig_em0="DHCP"
keymap="uk.iso"
sendmail_enable="NONE"
sendmail_msp_queue_enable="NO"
sendmail_outbound_enable="NO"
sendmail_submit_enable="NO"
sshd_enable="YES"
hiawatha_enable="YES"
e) Fix a minor default configuration problem with Hiawatha on FreeBSD and reboot, to make sure it works:
bsd# /usr/local/etc/rc.d/hiawatha start
Starting hiawatha.
Error creating work directory '/var/lib/hiawatha'
bsd# mkdir /var/lib
bsd# /usr/local/etc/rc.d/hiawatha start
Starting hiawatha.
bsd# init 6
f) Quick test to see if everything works as intended:
bsd# curl 127.0.0.1
(Standard welcome page for Hiawatha appears)
g) Set up FCGI:
bsd# cd /usr/ports/www/fcgi/
bsd# make
bsd# make install
===> Installing for fcgi-devkit-2.4.0
===> Generating temporary packing list
===> Checking if www/fcgi already installed
Making install in libfcgi
/bin/sh ../mkinstalldirs /usr/local/lib
/bin/sh /usr/local/bin/libtool --mode=install /usr/bin/install -c -o root -g wheel libfcgi.la /usr/local/lib/libfcgi.la
libtool: install: /usr/bin/install -c -o root -g wheel .libs/libfcgi.so.0 /usr/local/lib/libfcgi.so.0
libtool: install: (cd /usr/local/lib && { ln -s -f libfcgi.so.0 libfcgi.so || { rm -f libfcgi.so && ln -s libfcgi.so.0 libfcgi.so; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libfcgi.so.0 libfcgi.so || { rm -f libfcgi.so && ln -s libfcgi.so.0 libfcgi.so; }; })
libtool: install: /usr/bin/install -c -o root -g wheel .libs/libfcgi.lai /usr/local/lib/libfcgi.la
libtool: install: /usr/bin/install -c -o root -g wheel .libs/libfcgi.a /usr/local/lib/libfcgi.a
libtool: install: chmod 644 /usr/local/lib/libfcgi.a
libtool: install: ranlib /usr/local/lib/libfcgi.a
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/bin/sh /usr/local/bin/libtool --mode=install /usr/bin/install -c -o root -g wheel libfcgi++.la /usr/local/lib/libfcgi++.la
libtool: install: warning: relinking `libfcgi++.la'
libtool: install: (cd /usr/ports/www/fcgi/work/fcgi-2.4.0/libfcgi; /bin/sh /usr/local/bin/libtool --mode=relink c++ -O2 -pipe -fno-strict-aliasing -o libfcgi++.la -lfcgi -rpath /usr/local/lib fcgio.lo )
libtool: relink: c++ -shared -nostdlib /usr/lib/crti.o /usr/lib/crtbeginS.o .libs/fcgio.o -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -lfcgi -L/usr/lib -lstdc++ -lm -lc -lgcc_s /usr/lib/crtendS.o /usr/lib/crtn.o -Wl,-soname -Wl,libfcgi++.so.0 -o .libs/libfcgi++.so.0
libtool: install: /usr/bin/install -c -o root -g wheel .libs/libfcgi++.so.0T /usr/local/lib/libfcgi++.so.0
libtool: install: (cd /usr/local/lib && { ln -s -f libfcgi++.so.0 libfcgi++.so || { rm -f libfcgi++.so && ln -s libfcgi++.so.0 libfcgi++.so; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libfcgi++.so.0 libfcgi++.so || { rm -f libfcgi++.so && ln -s libfcgi++.so.0 libfcgi++.so; }; })
libtool: install: /usr/bin/install -c -o root -g wheel .libs/libfcgi++.lai /usr/local/lib/libfcgi++.la
libtool: install: /usr/bin/install -c -o root -g wheel .libs/libfcgi++.a /usr/local/lib/libfcgi++.a
libtool: install: chmod 644 /usr/local/lib/libfcgi++.a
libtool: install: ranlib /usr/local/lib/libfcgi++.a
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Making install in cgi-fcgi
/bin/sh ../mkinstalldirs /usr/local/bin
/bin/sh /usr/local/bin/libtool --mode=install install -s -o root -g wheel -m 555 cgi-fcgi /usr/local/bin/cgi-fcgi
libtool: install: install -o root -g wheel -m 555 -s .libs/cgi-fcgi /usr/local/bin/cgi-fcgi
Making install in examples
Making install in include
/bin/sh ../mkinstalldirs /usr/local/include
install -o root -g wheel -m 444 fastcgi.h /usr/local/include/fastcgi.h
install -o root -g wheel -m 444 fcgi_stdio.h /usr/local/include/fcgi_stdio.h
install -o root -g wheel -m 444 fcgiapp.h /usr/local/include/fcgiapp.h
install -o root -g wheel -m 444 fcgimisc.h /usr/local/include/fcgimisc.h
install -o root -g wheel -m 444 fcgio.h /usr/local/include/fcgio.h
install -o root -g wheel -m 444 fcgios.h /usr/local/include/fcgios.h
/bin/sh ./mkinstalldirs /usr/local/include
install -o root -g wheel -m 444 fcgi_config.h /usr/local/include/fcgi_config.h
===> Compressing manual pages for fcgi-devkit-2.4.0
===> Running ldconfig
/sbin/ldconfig -m /usr/local/lib
===> Registering installation for fcgi-devkit-2.4.0
===> SECURITY REPORT:
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/lib/libfcgi.so.0
If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type 'make deinstall'
to deinstall the port if this is a concern.
For more information, and contact details about the security
status of this software, see the following webpage:
http://www.fastcgi.com/
h) Compile test FCGI application and run it:
bsd# cd /usr/local/www/hiawatha/
bsd# cat fastcgi.c
#include <stdio.h>
#include <stdlib.h>
#include <fcgiapp.h>
#define printf(...) FCGX_FPrintF(request->out, __VA_ARGS__)
#define get_param(KEY) FCGX_GetParam(KEY, request->envp)
void handle_request(FCGX_Request *request) {
char *value;
printf("Content-Type: text/plain\r\n\r\n");
if ((value = get_param("REQUEST_METHOD")) != NULL) {
printf("%s ", value);
}
if ((value = get_param("REQUEST_URI")) != NULL) {
printf("%s", value);
}
if ((value = get_param("QUERY_STRING")) != NULL) {
printf("?%s", value);
}
if ((value = get_param("SERVER_PROTOCOL")) != NULL) {
printf(" %s", value);
}
printf("\n");
}
int main(void) {
int sock;
FCGX_Request request;
FCGX_Init();
sock = FCGX_OpenSocket(":2005", 5);
FCGX_InitRequest(&request, sock, 0);
while (FCGX_Accept_r(&request) >= 0) {
handle_request(&request);
FCGX_Finish_r(&request);
}
return EXIT_SUCCESS;
}
bsd# g++ -Wall -I /usr/local/include -L /usr/local/lib -lfcgi fastcgi.c -o fastcgi
bsd# ./fastcgi
^Z
Suspended
bsd# bg
[1] ./fastcgi &
bsd# sockstat | grep fastcgi
root fastcgi 4151 3 tcp4 *:2005 *:*
i) Configure Hiawatha:
bsd# /usr/local/etc/rc.d/hiawatha stop
Stopping hiawatha.
Waiting for PIDS: 675.
bsd# vi /usr/local/etc/hiawatha/hiawatha.conf
/usr/local/etc/hiawatha/hiawatha.conf: 105 lines, 2214 characters.
bsd# cat /usr/local/etc/hiawatha/hiawatha.conf
# Hiawatha main configuration file
#
# GENERAL SETTINGS
#
#ServerId = www-data
ConnectionsTotal = 150
ConnectionsPerIP = 10
SystemLogfile = /var/log/hiawatha/system.log
GarbageLogfile = /var/log/hiawatha/garbage.log
# BINDING SETTINGS
# A binding is where a client can connect to.
#
Binding {
Port = 80
# Interface = 127.0.0.1
# MaxKeepAlive = 30
# TimeForRequest = 3,20
}
#
#Binding {
# Port = 443
# Interface = ::1
# MaxKeepAlive = 30
# TimeForRequest = 3,20
# SSLcertFile = hiawatha.pem
#}
# BANNING SETTINGS
# Deny service to clients who misbehave.
#
#BanOnGarbage = 300
#BanOnMaxPerIP = 60
#BanOnMaxReqSize = 300
#KickOnBan = yes
#RebanDuringBan = yes
# COMMON GATEWAY INTERFACE (CGI) SETTINGS
# These settings can be used to run CGI applications. Use the 'php-fcgi'
# tool to start PHP as a FastCGI daemon.
#
#CGIhandler = /usr/bin/perl:pl
#CGIhandler = /usr/bin/php-cgi:php
#CGIhandler = /usr/bin/python:py
#CGIhandler = /usr/bin/ruby:rb
#CGIhandler = /usr/bin/ssi-cgi:shtml
#CGIextension = cgi
#
FastCGIserver {
FastCGIid = QFastCGI
ConnectTo = 127.0.0.1:2005
SessionTimeout = 30
}
# URL TOOLKIT
# This URL toolkit rule was made for the Banshee PHP framework, which
# can be downloaded from http://www.hiawatha-webserver.org/banshee
#
UrlToolkit {
ToolkitID = bsd_toolkit
RequestURI exists Return
Match .* UseFastCGI QFastCGI
}
# DEFAULT WEBSITE
# It is wise to use your IP address as the hostname of the default website
# and give it a blank webpage. By doing so, automated webscanners won't find
# your possible vulnerable website.
#
Hostname = 127.0.0.1
WebsiteRoot = /usr/local/www/hiawatha
StartFile = index.html
AccessLogfile = /var/log/hiawatha/access.log
ErrorLogfile = /var/log/hiawatha/error.log
#ErrorHandler = 404:/error.cgi
# VIRTUAL HOSTS
# Use a VirtualHost section to declare the websites you want to host.
#
VirtualHost {
Hostname = bsd.speedport.ip
WebsiteRoot = /var/www/bsd/public
AccessLogfile = /var/www/bsd/log/access.log
ErrorLogfile = /var/www/bsd/log/error.log
TimeForCGI = 5
UseToolkit = bsd_toolkit
}
# DIRECTORY SETTINGS
# You can specify some settings per directory.
#
#Directory {
# Path = /home/baduser
# ExecuteCGI = no
# UploadSpeed = 10,2
#}
j) Set up directories and restart Hiawatha:
bsd# mkdir -p /var/www/bsd/public
bsd# mkdir -p /var/www/bsd/log
bsd# /usr/local/etc/rc.d/hiawatha start
Starting hiawatha.
bsd# curl bsd.speedport.ip
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>404 - Not Found</title>
<style type="text/css">BODY { color:#ffffff ; background-color:#00000a }
DIV { font-family:sans-serif ; font-size:30px ; letter-spacing:20px ; text-align:center ; position:relative ; top:250px }
</style>
</head>
<body>
<div>404 - Not Found</div>
</body>
</html>
bsd# touch /var/www/bsd/public/index.html
bsd# curl bsd.speedport.ip
bsd#
Back at square one, unfortunately.
I hope this is detailed enough for you to be able to spot any errors I have made in the setup and configuration.