Montag, 12. September 2011

Creates minimal (simple, portable) Http Server (Apache, Xampp)

Following post describes how to build a minimal (portable) Http Server with the help of apache (xampp project)




Download an extract a Xampp Project (e.g. http://freefr.dl.sourceforge.net/project/xampp/XAMPP%20Windows/1.7.3/xampp-win32-1.7.3.zip)

Create following folder structure

PortableHttpServer
|-   apache|    |- bin
|    |- conf
|    |- logs
|    |- modules
|
|-   htdocs


Copy following files:


xampp/apache/bin/httpd.exe   => apache/bin
xampp/apache/bin/libapr-1.dll   => apache/bin
xampp/apache/bin/libapriconv-1.dll   => apache/bin
xampp/apache/bin/libaprutil-1.dll   => apache/bin
xampp/apache/bin/libhttpd.dll   => apache/bin


xampp/apache/conf/mime.types => apache/conf


xampp/apache/modules/mod_dir.so => apache/modules
xampp/apache/modules/mod_mime.so => apache/modules


Create httpd.conf file in apache/conf with following content


#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 0.0.0.0:80
#Listen [::]:80
Listen 4444


#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule dir_module modules/mod_dir.so
LoadModule mime_module modules/mod_mime.so


#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:4444


#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "../htdocs"


#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.htm
</IfModule>
  
#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain


#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain


<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig "conf/mime.types"


    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz


</IfModule>

Create start.bat file in PortableHttpServer with following content:


cd "%~dp0apache/bin/"
httpd.exe -f conf/httpd.conf


pause


Create index.html in htdocs with following content:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Title of Webpage</title>
  </head>
  <body>
    <p>Content of webpage</p>
  </body>
</html>

Start start.bat
Open webbrowser with following url: http://localhost:4444