cgore.comcgore@cgore.commicroblogblogphotosChristianitycryptographyjournalingoutdoorsmy master's thesisprogramming
Thinking Bicycle

# Chris Gore: Programming: Lisp: SBCL and Apache

Strangely, one of the biggest hurdles to writing web code in SBCL is at the very start of the game: getting anything at all to show up in Apache. SBCL is a great language for CGI, but not without a few tweaks and weird flags. The first problem is in Apache itself. If you want Apache to recognize somefile.lisp as a CGI executable and not just plaintext, you will need the following line in your Apache configuration file:

AddHandler cgi-script .lisp

If you want to be able to have the main page for a directory be one of these Lisp CGI scripts, you will also need to add the following line to your Apache configuration file:

DirectoryIndex index.lisp

You will also need to make sure that CGIs are allowed in the directory you are trying to keep the script in. That is easy enough.

Here comes the hard part though, getting SBCL to play nice as a CGI script: not printing miles of debugging info, banners, and who knows what else, taking simple input from stdin and putting its output simply to stdout, and so forth. In my case I also load a special lisp core, although that is entirely optional. Specifically, for this website I have a bash file named cgore-runlisp on the path with the following contents:

#! /bin/bash

/usr/bin/sbcl \
--core /var/www/cgore.com/source/cgore.core \
--noinform --disable-debugger \
--eval '(set-dispatch-macro-character
## #!
(lambda (stream bang number)
(declare (ignore bang number))
--load \$1 --eval '(quit)'
#! /usr/bin/env cgore-runlisp
" more specifically: it is my absolute favorite way to tell a computer to do things."))