I hadn't heard about Lighttpd (Lighty) web server before I started to be interested in Ruby on Rails (RoR). Lighttpd is fast, scalable, secure, flexible and lightweight webserver which in RoR community is preferred production web server. One of the main advantages of Lighttpd compared to Apache, for example, is the built in support for FastCGI and very easy yet flexible configuration.
When I was preparing the production environment for one of the RoR applications I was working on lately, I found that even though there is quite a lot of HowTos for installing lighttpd on linux and MacOS, there is not a single one that I could find that would describe this procedure on Solaris / OpenSolaris OS.
While setting up the production environment I got stuck on some steps, and I hope that this HowTo will help anyone trying to deploy his RoR application on Solaris and to avoid problems I had.
Targeted configuration: Solaris 10 + Lighttpd + FastCGI + SSL
1. Prerequisites I started out with the core installation of Solaris 10, this means that I needed to add some packages. Before you start, make sure you have these Solaris packages installed:
- SUNWhea >>> needed by lighttpd
- SUNWtoo >>
- SUNWlibmr >>> needed by fastcgi
- SUNWlibm >>
From blastwave.org via pkg-get get:
- openssl >>> needed by lighttpd for ssl
- option 1) 202MB - works
- option 2) 365MB - haven't tried
Now we should be ready to start.
At first we should install Lighttpd which can be downloaded from here. (I used gcc to compile this one)
./configure --with-openssl=/opt/csw --with-ldap --with-bzip2 --with-zlibThe output from the configure command should end like this:
Features: enabled: auth-crypt auth-ldap compress-bzip2 compress-deflate compress-gzip large-files network-ipv6 network-openssl regex-conditionals ... ...
Make sure the "network-openssl" is in the list of enabled features, if it is not there, check the output from configure tests and if you see that openssl was found and right below it is:
checking for BIO_f_base64 in -lcrypto... nocheck your configure arguments and make sure that --with-openssl=/path/to/openssl is set correctly (if installed via pkg-get it will resided in /opt/csw). If this is not done properly everything will compile correctly but the --with-openssl option will be ignored silently!
Let's finish up the installation:
make make installTest if everything went well with -v switch
$ ligttpd -v lighttpd-1.4.11 (ssl) - a light and fast webserver Build-Date: Aug 30 2006 15:19:28If there is no "(ssl)" after the version, something is wrong, check if you set --with-openssl=/path correctly.
Now we need to install FastCGI which can be downloaded from here:
./configure --prefix=/usr/local make make install4. ruby-fcgi
Next step is to install ruby-fcgi bindings. This is where I got really stuck. To be able to install this, you need the Sun C Compiler mentioned earlier. If you installed ruby and ruby gems via pkg-get as I did, it comes preconfigured to use Sun compiler by default, even if one is not installed. And if you don't have this compiler you will see all sorts of weird errors when installing gems with native extensions.
Once you have the compiler, installation is trivial. If you are building it manually, download sources here:
ruby install.rb config -- --with-fcgi-dir=/usr/local ruby install.rb setup ruby install.rb installor when using ruby gems:
gem install fcgi -- --with-fcgi-dir=/usr/localNote the double "
--", that is not a typo, it's simply the way how to send parameters to
If you see an error like this:
install.rb: entering config phase... ---> lib <--- lib ---> ext ---> ext/fcgi /opt/csw/bin/ruby /root/ruby-fcgi-0.8.6/ext/fcgi/extconf.rb checking for fcgiapp.h... yes checking for FCGX_Accept() in -lfcgi... no <--- ext/fcgi <--- extNote this part:
checking for fcgiapp.h... yes checking for FCGX_Accept() in -lfcgi... noIt most likely means that you are using GCC and not Sun C Compiler, check if cc in your path is pointing to Sun C Compiler, you might also check if the environmental variable CC is not set to gcc. Let's test if fcgi and ruby-fcgi bindings were correctly installed by these commands in irb:
irb(main):001:0> require 'fcgi.so' => true irb(main):001:0> require 'fcgi' => trueIf both "require" calls return true, you have successfully installed FastCGI and ruby is able to invoke it. 5. SSL Certificate
If you don't have your server certificate yet, you can create a self signed one like this:
openssl req -new -x509 -keyout server.pem -nodes -out server.pem -days 10006. Configuring Lighty
Let's start the server
lighttpd -f lighttpd.conf
I hope that these instructions helped you to get Lighty on Solaris.
If you have other recommendations or have problems with the installation, feel free to leave a comment.
PS: A big thanks to my friend J who helped me figure out that you need Sun C compiler for ruby-fcgi to compile.
UPDATE: added reference to SUNWbtool and SUNWsprot packages in case you want to compile everything with Sun's compiler.