Using the Apache Web Server with CL on Win32
Friday, November 5, 2004
Last month, I posted
about different CL web server options. In the second category that I
discussed ("Lisp servers that interact with another web server"), I
mentioned Marc Battyani's
mod_lisp, an Apache web
server based option that is implemented as an Apache module. I discussed the various
pros and cons of the different CL web server options in my earlier
post, so I won't go over them again here. However, one limitation that
I mentioned with the Apache-based alternatives was that it was a more
complicated alternative and required "multiple product (and,
potentially, programming language) skills". I decided to see for
myself how difficult it would be for a newbie to get started with an
Apache-based web server alternative.
First of all, some caveats. Although I have used various Java-based web/application server products, I had never before installed or setup Apache. Therefore, I can be considered a complete Apache newbie. Second, I wanted to create an Apache-based environment that would easily handle most of the types of things that I would want to do. Although mod_lisp manages the low-level communication between Apache and CL, I would need some extra helper packages. Third, although I have access to both a Linux box and a Mac OS X box, my primary PC is a Windows/2000 machine (Note: I don't want people to think that I'm suggesting you actually use a Win32 box as a web server, especially if you're concerned about security; however, for testing purposes, this was the most convenient machine for me to use). Most (maybe even all?) of the Apache/mod_lisp users on c.l.l. seem to be Linux users so I would probably be hard-pressed to find help if I hit any snags. In addition, many people (and the Apache web site itself) do not recommend running a web server on a Win32 box. So, I was expecting problems.
Surprisingly, things went very smoothly! Here is a step-by-step account of what I did to get things going (Note: the following worked with both ACL 7.0 and LispWorks 4.3 on Win/2000):
- I downloaded and installed the Apache 1.3 binary distribution for Win32. When installing, I took all the defaults except for choosing to install it in "c:\bin\apache" rather than the default "c:\Program Files\Apache Group\" location. After installing, I ran Apache.exe and made certain that the Apache default page showed up in my browser when I went to "http://localhost".
- Marc Battyani provides a pre-built version of mod_lisp for Win32. So, I downloaded the zip file and extracted the contents into the "C:\bin\apache\Apache\modules" directory.
- Since mod_lisp only provides a low-level interface between Apache
and CL, I decided to use the
CL-WHO libraries that
Edi Weitz developed to provide a higher level of abstraction on
top of the mod_lisp layer. There are a number of pre-reqs for these
libraries, so I downloaded them as well and unpacked all of the
libraries under my "c:\usr\home\lisp" directory. Here are all the
CL packages that I downloaded:
- TBNL: A toolkit developed by Edi Weitz for building dynamic websites. It provides facilities like automatic session handling (with and without cookies), logging to Apache's log files, customizable error handling, and easy access to GET and POST parameters sent by the client.
- CL-WHO: A Lisp markup language developed by Edi Weitz for generating HTML from CL.
- KMRCL: A collection of general purpose utilities used by a number of Kevin Rosenberg's CL packages.
- MD5: An implementation by Pierre R. Mai of the cryptographic Message-Digest protocol from RSA Data Security, Inc.
- CL-BASE64: A library developed by Kevin Rosenberg for base64 encoding and decoding.
- CL-PPCRE: A portable regular expression library developed by Edi Weitz.
- URL-REWRITE: A small package developed by Edi Weitz which can be used to programmatically rewrite (X)HTML documents.
- ASDF: Most people will already have this one; however, I'm including it for completeness. It's Daniel Barlow's system definition facility and it's used for building all the other packages.
- I had to modify the Apache configuration file
"C:\bin\apache\Apache\conf\httpd.conf" so that requests for
dynamic content would be passed on to mod_lisp and TBNL. I decided
to use the test program that comes with TBNL as the dynamic request
handler so just put in the modifications that Edi
LoadModule lisp_module modules/mod_lisp.so ... AddModule mod_lisp.c LispServer 127.0.0.1 3000 "tbnl" <Location /tbnl> SetHandler lisp-handler </Location>I subseqently stopped and re-started Apache so that the changes would be recognized.
- I ran the following CL code to load the necessary
libraries and to start the example TBNL program:
(defvar *lisp-dirs* "c:/usr/home/lisp/" "Root location of CL library installs") (load (concatenate 'string *lisp-dirs* "asdf/asdf.lisp")) (setf asdf:*central-registry* '(*default-pathname-defaults* (concatenate 'string *lisp-dirs* "cl-base64-3.3.1/") (concatenate 'string *lisp-dirs* "cl-ppcre-0.9.0/") (concatenate 'string *lisp-dirs* "cl-who-0.4.3/") (concatenate 'string *lisp-dirs* "kmrcl-1.77/") (concatenate 'string *lisp-dirs* "md5-1.8.4/") (concatenate 'string *lisp-dirs* "tbnl-0.2.12/") (concatenate 'string *lisp-dirs* "url-rewrite/"))) (asdf:oos 'asdf:load-op :tbnl-test) (tbnl:start-tbnl)
- I then opened a browser and entered the URL "http://localhost/tbnl/test". A dynamically-generated page was generated and I could select from a list of options that produce other dynamically-generated pages.
- To shut things down, I entered "(tbnl:stop-tbnl)" in the CL REPL and "apache -k shutdown" at a command line.