Updated 2011-04-15 11:45:29 by RLE

I want to learn how to set up a server on my Windows 98 machine so I can run wikit under cgi. It looks like setting up the server is my first step. This page will document my learning process about servers. I am going to look at Personal Web Server first and see if I can get that going. Any tips? Point me in the right direction? --DGR 10/1/00

OK, I found SimpleServer:WWW for Windows at http://www.analogx.com/contents/download/network/sswww.htm and am installing it as my standalone server. --DGR 10/3/00

As this is the tclers wiki, a link to tclhttpd is more than needed...

May 10, 2002 - There are no doubt lots of ways to get there. Here's the approach I would suggest:

  • get tclhttpd as a scripted document [1]
  • get the tclkitsh.exe runtime [2] (note that you don't want the tclkit GUI version)
  • get the latest wikit, see "nwikit" at [3]

Now, "tclkitsh tclhttpd" ought to start the web server (port 8015 is the default, I think). You should be able to see it by browsing to http://127.0.0.1:8015/.

The way to start wikit, is to create a bat file, containing:
        @tclkitsh nwikit.bin %1 %2 %3

When launched as CGI, it will do the right thing (such as create a wikit.tkd to hold the wiki page contents). Note that you need tclkit, not tclkitsh, if you want to use wikit in local Tk mode (i.e. "tclkit nwikit.bin").

The missing piece is that I'm not familiar enough with tclhttpd to say how one connects both pieces together... (if you are reading this and know how to make it all work together, please feel free to amend this page).

-jcw

Dec 30, 2002 Here's how I got Wikit working with Tclhttpd, under Windows.

First I made a .cgi file that called Wikit. It sets some WIKIT_ environment variables and calls Wikit, and at first failed to display anything. This is because under Windows TCL child processes can't send their output to sockets. Tclhttpd redirects stdout to the socket, but Windows refuses the redirection.

When I redirect Wikit's output to a scratch file and then have the .cgi file send it to stdout, it works.

Then I added the static files. I put a file in the tclhttpd/custom directory minor tclhttpd glitch which redirects any URL beginning with 'wikit' to a TCL routine WikitDomain. This routine first checks whether there is a static file already made with the correct name, if so it displays it. Otherwise it redirects to the .cgi file to create that file for next time and display it now. The only problem I found was that the Windows static files have names like /3.html while Wikit itself points to names like /3 . That and the failure of exec to allow writing to sockets are the only things that looked like they might be different in Windows.

There may be problems with unset CGI environment variables. I noticed some intermittent problems that I'm not sure are gone. I'm posting the code partly because I find it easier to fix something that mostly works than to create something perfect from scratch, and maybe that's true for others too.

# I expect tclhttpd has a way to let you trap 'page not found' in a single domain and # run a simple redirect then. But I don't know how to do that so I had to do it myself. # This code runs whenever a URL comes in for the /wikit domain. # It looks for a page that matches the URL in the .... /htdocs/wikit/ directory. # If it finds one, it displays that. Otherwise it runs the wikit.cgi script which does stuff.

wikitsetup.tcl in /tclhttpd/custom/ folder
 set myroot C:/tcl/httpdist/tclhttpd/htdocs/
 set env(WIKIT_CACHE) [file join $myroot wikit/]

 set env(WIKIT_DUMP)  [file join $myroot dump/review.txt]
 set env(WIKIT_ADMIN) 1

 Url_PrefixInstall /wikit [list WikitDomain /wikit]

 proc WikitDomain {prefix sock suffix} {
   upvar #0 Httpd$sock data outfile outfile
   tclLog "prefix $prefix sock $sock suffix $suffix"
   if {[llength $suffix] == 0} {set suffix /0}
   if {[string length $suffix] < 2} {set suffix /0}
   set myfile [string range $suffix 1 end]
   set outfile [join {$::env(WIKIT_CACHE)$suffix html} .]
   if {[file exists $outfile]} {
     Httpd_ReturnFile $sock text/html $outfile
   } else {Httpd_RedirectSelf ../cgi-bin/wikit.cgi$suffix $sock
   }
 }

wikit.cgi in /tclhttpd/htdocs/cgi-bin/ folder
 set env(WIKIT_BASE) http://127.0.0.1:8015/wikit/

 set env(WIKIT_DUMP)  C:/tcl/httpdist/tclhttpd/htdocs/dump/review.txt
 set env(WIKIT_ADMIN) 1

 regexp {\d+} $env(PATH_INFO) mufile
 if {[llength $mufile] > 1} {set mufile [lindex $mufile 1]}
 set env(REDIRECT_URL) /wikit/$mufile
 exec > rrrr.txt tclkitsh c:/tcl/wikit.kit c:/tcl/wikit.tkd
 set rr [open rrrr.txt]
 fcopy $rr stdout
 close $rr

It would be far better to integrate wikit into tclhttpd. tclhttpd is designed to make it easy to add custom modules. Wikit without threads was said to use CGI to avoid blocking problems, while tclhttpd was designed to never block. My first attempts at that found that tclhttpd worked fine under tclkitsh, and could embed Wikit. Embedded Wikit is different enough that I haven't pursued that yet. Jonah Thomas

CL has set up tclhttpd on vanilla Win* machines several times, and found CGI configuration a snap. The only detail he remembers for today, though, is that reading the tclhttpd documentation sufficed. Perhaps he'll return later with a fuller explanation.