1tclhttpd(1)                   TclPro Applications                  tclhttpd(1)
2
3
4

NAME

6       tclhttpd - Tcl Web Server
7
8

SYNOPSIS

10       tclsh httpd.tcl ?options?
11
12

OPTIONS

14       -help          Displays usage information, then exit without doing any‐
15                      thing.
16
17       -config filename
18                      Name   of   the   configuration    file    (e.g.    tcl‐
19                      pro/bin/tclhttpd.rc).
20
21       -main filename Name   of   the   per-thread   main  script  (e.g.  tcl‐
22                      pro/bin/httpdthread.tcl).
23
24       -docRoot directory
25                      The  root  directory  of  your  web  pages  (e.g.,  tcl‐
26                      pro/tclhttpd/htdocs).
27
28       -port value    HTTP listening port.  Defaults to 8015.
29
30       -host value    The hostname for the HTTP listening socket.
31
32       -ipaddr value  Interface the server should bind to.
33
34       -webmaster email
35                      Email contact for webmaster.
36
37       -uid userid    User name or ID for server process user ID.
38
39       -gid groupid   Group name or ID for server process group ID.
40
41       -threads num   Run with num worker threads.  Requires a thread safe Tcl
42                      shell.
43
44       -library directory
45                      Directory to add to the auto_path.
46
47       -verbose       Causes extra print statements during startup.
48
49

DESCRIPTION

51       TclHttpd is a simple, extensible,  embeddable  Web  Server.   The  best
52       source of documentation is in HTML distributed with the server.
53
54       To  start  the  server,  simply  run the httpd.tcl script with tclsh or
55       wish.  For example, this starts the server on the standard  Web  server
56       port, 80.  tclsh <installdir>/bin/httpd.tcl -port 80 Note that you must
57       start the server as root if you use port numbers less than 1024 on UNIX
58       systems.   If you want the server process to run under a different user
59       than root, which is strongly recommended, then use the  -uid  and  -gid
60       options.   This  way the server can start as root, open the socket, and
61       then switch to a less privileged account.
62
63

CONFIGURATION AND CUSTOMIZATION

65       The main script depends on a per-thread  Tcl  script,  httpdthread.tcl,
66       and  a  configuration file, tclhttpd.rc.  These have configuration set‐
67       tings and the start up code for the web server.
68
69       The configuration file can be used to set the port, user ID, and  other
70       values  described  in  the Options list above.  You can configure addi‐
71       tional features such as log file location, and more,  by  editting  the
72       configuration  file.  There is an explanation about each option, so you
73       can make a copy of the configuration file and  try  out  new  settings.
74       tclsh httpd.tcl -config myserver.rc
75
76       If you plan to extend Tcl Httpd with your own code, you may need to add
77       initialization code to  bin/httpd.tcl  and  bin/httpdthread.tcl.   This
78       code  is  typically  a "package require" for your module and one or two
79       calls to initialize it.  For example,  this  code  the  httpdthread.tcl
80       enables  a /debug URL implementation that lets you examine the state of
81       the server.  package require httpd::debug Debug_Url /debug Debug
82
83       The web server should have access to any Tcl  package  installed  along
84       with your Tcl installation.  Consult the on-line HTML documentation for
85       a more indepth discussion of programming the server.
86
87

WEB PAGE TEMPLATES

89       TclHttpd supports a flexible template system that embeds Tcl code  into
90       your  HTML  pages.   The  Web Server processes the Tcl, which typically
91       generates bits and pieces of your HTML page, and delivers the result to
92       the client transparently.  You can cache the results of processing your
93       templates, or you can have pages that are processed dynamically on each
94       access.
95
96       Any page that ends in ".tml" is treated like an HTML+Tcl template page.
97       The Web Server uses the Tcl subst command to  replace  commands  within
98       brackets,  [  and  ],  and variable references, like $Phone, with their
99       value.  Backslash processing is also done.  The main thing you need  to
100       watch  out  for  is  putting  literal dollar amounts in your templates.
101       You'll need to protect your $ with a backslash: The price  is  \$10.00.
102       The  ".tml"  files in the sample htdocs directory structure should give
103       you examples to work from.
104
105       Try to limit the Tcl code in your pages to simple procedure calls,  and
106       put the procedure definitions in per-directory files named ".tml".  The
107       name of this file is confusing: each directory can contain a file named
108       "dot-t-m-l" (.tml) that should contain Tcl code.  These files are auto‐
109       matically loaded before any templates in that directory (or subdirecto‐
110       ries) is processed.
111
112       For  example, first create a new directory of the htdocs directory that
113       comes with TclHttpd.  mkdir htdocs/mystuff Next, put the following into
114       htdocs/mystuff/.tml package require htmlutils
115
116       # A procedure to format the date the way you like it proc MyDate {{sec‐
117       onds {}}} {
118           if {[string length $seconds] == 0} {      set seconds  [clock  sec‐
119       onds]
120           }
121           return  [clock  format  $seconds -format "%B %m, %Y"] } # Some page
122       settings set bgcolor pink Now, any page in the htdocs/mystuff directory
123       can use the MyDate procedure in a template.  Finally, put the following
124       into htodcs/mystuff/index.tml <title>My Stuff</title> <body  text=black
125       bgcolor=$bgcolor>  <h2>My  Stuff</h2>  [MyDate] <br> Page content here.
126       <p> Send email to [Mailto [Doc_Webmaster]].  The  bgcolor  variable  is
127       set  in  the .tml file and used in the BODY tag.  The Mailto is part of
128       the htmlutils package that was required by the .tml file.  The Doc_Web‐
129       master  procedure  is  built  into  TclHttpd.  The MyDate procedure was
130       added by you, and is shared by any page in or below the  htdocs/mystuff
131       directory.
132
133

KEYWORDS

135       Web Server, HTTP, TclHttpd
136
137
138
139TclPro                                                             tclhttpd(1)
Impressum