Although i’m a newby on common lisp world, i decided to implement a simplistic mvc framework with common lisp. So i configured my recently owned linode vps with nginx, sbcl, hunchentoot, cl-sql, also installed emacs and slime for a convenient development environment which nicely supports remote connection to a lisp interpreter instance using slime’s swank server. Since i succeed with my own configuration, i want to share my experiments from here to lighten another lispers. But please pay attention that all instructions i share here is in the responsibility of your own risk of usage. The operating system i use is Etch release of Debian. Note that the version of applications that i use for examples should change in the future.
First of all let’s get nginx installed on our server, so go and get nginx tarball from nginx homepage. Download and unzip it to your home directory like this:
$ cd
$ wget http://sysoev.ru/nginx/nginx-0.6.34.tar.gz
$ tar -xzvf nginx-0.6.34.tar.gz
Enter to the unzipped directory and perform a user-wide installation with its prerequisites.
$ cd
$ apt-get install libpcre3-dev
$ apt-get install zlib1g-dev
$ mkdir nginx
$ cd nginx-0.6.34
$ ./configure --prefix=$HOME/nginx
$ make
$ make install
$ cd
$ rm nginx-0.6.34 -rf
In the end you should have a nginx directory with a structure like this
nginx/client_body_temp
nginx/conf
nginx/fastcgi_temp
nginx/html
nginx/logs
nginx/proxy_temp
nginx/sbin
If you wonder why i preferred nginx instead of httpd (Apache Http Server) or lighttpd, my answer will not be so long. Our primary goal to use a http server in the frontend of hunchentoot is to serve static files (images, videos, javascript or css files etc.) efficiently so nginx has small memory footprint compared to httpd and very stable memory management compared to lighttpd. Yes i know lighttpd is also a nice web server with very well known modules handled on an easy configuration file but it has a very annoying memory leak problem that has not been solved yet (#758). Also you should read a post about nginx vs .lighttpd comparison here. For more information please refer to the survey of web server usage statistics at netcraft because i’ll not continue to talk about web server challanges anymore. There is a probably more adequate reason for me is that i loved nginx
Anyway, you can test your nginx installation:
$ cd
$ cd nginx
$ sudo sbin/nginx
$ curl localhost
If you see the nginx response you’re so lucky that you jump over the nginx installation flawlessly
Now let’s put hunchentoot on work starting with installation of sbcl first. Go to sbcl platform download page, choose an appropriate architecture on Linux row and get it with wget.
$ cd
$ wget http://puzzle.dl.sourceforge.net/sourceforge/sbcl/sbcl-1.0.23-x86-linux-binary.tar.bz2
$ tar -xjvf sbcl-1.0.23-x86-linux-binary.tar.bz2
Installation is quite easy:
$ cd
$ mkdir sbcl
$ cd sbcl-1.0.23-x86-linux-binary
$ INSTALL_ROOT=$HOME/sbcl sh install.sh
$ cd
$ rm sbcl-1.0.23-x86-linux-binary -rf
And now set ‘SBCL_HOME’ environment variable and add ‘$HOME/sbcl/bin’ to the ‘$PATH’ environment variable to get sbcl work anywhere
$ cd
$ echo "export SBCL_HOME=$HOME/sbcl/lib/sbcl" >> .bashrc
$ echo "PATH=$PATH:$HOME/sbcl/bin" >> .bashrc
$ . .bashrc
Great! Now see the sbcl works
$ sbcl
If you entered to the sbcl interpreter you got it.
The funniest part is when you are in a lisp interpreter, now we have to install hunchentoot to the system. Here we’ll require the help of ASDF (Another System Definition Facility) and ASDF-INSTALL (Remote or tarball interface tool for ASDF). ASDF is library dependency resolver system for common lisp world. Fortunately sbcl comes with ASDF and ASDF-INSTALL.
Hunchentoot is full blown pure common lisp web server. The structure of hunchentoot is fun to digg further and plays very well while designing web frameworks. I plan to write another post to give a hunchentoot tutorial in detail. Anyway..
Now you are ready to install hunchentoot but first we should better to define a variable that skips GPG signatures of lisp libraries globally.
$ cd
$ echo "(defparameter ASDF-INSTALL-CUSTOMIZE::*VERIFY-GPG-SIGNATURES* nil)" > $HOME/.asdf-install
Install the hunchentoot by ASDF_INSTALL. This tool resolves library names from cliki, the community common lisp wiki and library repository.
* (require 'asdf-install)
* (asdf-install:install 'hunchentoot)
* (quit)
In the end you’ll got the funniest pure lisp web server in the world. Start server by typing
$ cd
$ cat > hunch.lisp
(require 'asdf)
(asdf:operate 'asdf:load-op 'hunchentoot)
(hunchentoot:start-server :port 8080)
(read)
[CTRL-D]
$ sbcl --script hunch.lisp&
Yep!!, let’s checkout hunchentoot wheter it’s working
$ curl localhost:8080
If you see the hunchentoot’s response you’re ready to configure nginx to proxy web page requests to hunchentoot’s listening port. We’ll create a virtual host and proxy the requests that has paths end with ‘.html’ to the hunchentoot. First create a virtual server home directory.
$ cd
$ mkdir -p nginx/html/example.org/htdocs
Now open nginx configuration file and create a virtaul host configuration within the http node of the configuration file like below.
server {
listen 80;
server_name example.org;
location / {
root html/example.org/htdocs;
}
rewrite ^(.*)/$ $1/index.html;
location ~ .html$ {
proxy_pass http://127.0.0.1:8080;
}
}
You must now restart your nginx process to reload it’s configuration file
$ cd
$ sudo pkill nginx
$ cd nginx
$ sudo sbin/nginx
Yes! From now you have got a working lisp web server behind a powerful static content server. You should try it out by putting some static content to virtual host root directory and pointing your browser address to it. Please pay attention that we have proxied all html requests to hunchentoot, you should configure the nginx to handle any other regex.
Please if any command fails do not be upset cause i didn’t tried the commands line by line. I assume that you’re familiar unix/linux envirmenment and should correct if any instruction booms.
Hope this post help anyone interested…