The command line

GNU/Linux, web development and some other things

Gemstone/S and FastCGI With Lighttpd

I was reading the post from James Foster about configuring Apache/FastCGI for serving Seaside. I prefer Lighttpd because, as its name implies, it needs less resources to run. And with virtual hosting, as I have my servers, memory it is a big factor.

I followed the steps to install Gemstone/S in my machine. Instead of a hosted server, I used my laptop with my user as server.
After testing that Seaside was running OK in my machine, using:

miguel@laptop:~$ source /opt/gemstone/product/seaside/defSeaside
miguel@laptop:~$ startGemstone
miguel@laptop:~$ startSeaside_Hyper 8080

and navigating to:

http://localhost:8080/seaside

I stoped the Hyper Webserver with Ctrl+C.

Now to install lighttpd in my Debian GNU/Linux 4.0 etch machine. As root:

laptop:~# aptitude install lighttpd lighttpd-doc

and backup the default config file:

laptop:~# cp /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.bak

then use this configuration for lighttpd.conf:

# Modules activated
server.modules = ( “mod_access”, “mod_alias”, “mod_accesslog”, “mod_fastcgi” )
# Document root, maybe there you have other sites also
server.document-root = “/var/www/”
# logs
server.errorlog = “/var/log/lighttpd/error.log”
accesslog.filename = “/var/log/lighttpd/access.log”
# Welcome file
index-file.names = ( “index.html” )
# Do not server files beginning with
url.access-deny = ( “~”, “.inc” )
# Server config
server.port = 80
server.pid-file = “/var/run/lighttpd.pid”
dir-listing.encoding = “utf-8”
server.dir-listing = “disable”
server.username = “www-data”
server.groupname = “www-data”
# FastCGI
# Debug enabled, disable on production sites
fastcgi.debug = 1
# Do FastCGI for anything with prefix /seaside
# load-balancing with 3 hosts
# check-local disable searching the requested file in the lighttpd document root and
# forward the request to the fastcgi hosts
fastcgi.server = ( “/seaside” => (
    ( “host” => “127.0.0.1”, “port” => 9001, “check-local” => “disable”),
    ( “host” => “127.0.0.1”, “port” => 9002, “check-local” => “disable”),
    ( “host” => “127.0.0.1”, “port” => 9003, “check-local” => “disable”)
  )
)

Instead of starting Seaside over Gemstone/S with startSeaside_Hyper <port>, I used the provided script to start 3 gems for fastcgi as per James’ instructions:

miguel@laptop:~$ runSeasideGems start

This started 3 fastcgi gems, listening in ports 9001, 9002 and 9003.

Then I restarted lighttpd:

laptop:~# /etc/init.d/lighttpd restart
Stopping web server: lighttpd.
Starting web server: lighttpd.

And tested that the default index page for lighttpd (located in /var/www/index.html) was served statically (you can add anything here)  from the server document root (/var/www/), pointing the browser to:

http://localhost/

Finally, I tested that the /seaside part was correctly delegated to Gemstone/S using FastCGI, pointing the browser to:

http://localhost/seaside

This time I get the dispatcher from Seaside, from where you can navigate the links from Seaside without problems.

This way you can use, for example, blueprint for the CSS style of your app, or maybe TinyMCE, for having a full fledged text editor. All you have to do is to put them in a directory inside the document root of lighttpd (/var/www in this example) and in the Seaside application, you reference them with the absolut path to your website, for example:

http://mysite.com/styles/blueprint.css

or

http://mysite.com/tinymce/jscripts/tiny_mce/tiny_mce.js

So, the webserver to serve the static content of your site (faster) and Seaside to serve your webapp.

Enjoy.