Before an application can make it onto the Internet, it needs to go into a production environment and be deployed. This multi-part article series will show you how to do this for the Ruby-on-Rails ecommerce application we've been working on. It is excerpted from chapter 12 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
Application Deployment - Installing the Web Server: LightTPD (Page 3 of 4 )
The web server handles the communication between the userís browser and the Emporium application, which is running on the application server in one or more separate processes. When a request comes in from the Internet, the web server forwards the request (by acting as a reverse proxy and a load balancer) to one of the application servers.
In this book, we use LightTPD as the web server, because it is a tried-and-tested open source web server that, according to its homepage (http://www.lighttpd.net) is optimized for high performance. This claim is backed up by benchmarks, which put it among the fastest web servers available currently, and in front of the more popular Apache in some areas. LightTPD is easy to configure and includes themod_fastcgimodule, which can communicate with external FastCGI processes running Ruby on Rails applications. After being forwarded by LightTPD, the request is processed by Ruby on Rails, and the output is sent back to the client, again using the FastCGI protocol.
Here, we provide instructions for installing LightTPD from source on Ubuntu Linux. You can also find a binary installation package for Windows, Mac OS X, and most Linux distributions athttp://www.lighttpd.net/download.
Although some commands are specific to Ubuntu Linux, the installation instructions are generally applicable to most Linux/Unix platforms, with some exceptions, such as how dependencies are installed. See the Rails wiki (wiki.rubyonrails.org) and other online resources for detailed instructions on how to set up and configure the software on other platforms.
You also need to install the compiler provided by GCC, which is available through thebuild-essentialspackage in Ubuntu Linux:
$ sudo apt-get install build-essentials
Next, download the latest available stable source LightTPD package fromhttp://www.lighttpd.net/downloadto a directory on your production server (such as/usr/local/srcor/tmp). Then execute the following commands one by one (weíve omitted the output of the commands here for the sake of clarity):
$ tar xzvf lighttpd-1.x.x.tar.gz $ cd lighttpd-1.x.x $ ./configure --with-openssl $ make $ sudo make install
These commands extract the package and compile the source.
Tip For more information about compiling LightTPD, refer to theINSTALLandREADMEfiles, which are located inside the source package.
As we said, you need to install both the OpenSSL package and the SSL development libraries and headers in order to run LightTPD. If you didnít install them, you would get an error similar to the one shown here when starting LightTPD:
SSL: ssl requested but openssl support is not compiled in
You can verify that the required dependencies are found by inspecting the output of theconfigure command:
. checking for OpenSSL... yes checking openssl/ssl.h usability... yes checking openssl/ssl.h presence... yes . . checking pcre.h usability... yes checking pcre.h presence... yes checking for pcre.h... yes checking for deflate in -lz... yes checking zlib.h usability... yes checking zlib.h presence... yes checking for zlib.h... yes .
If you donít see any errors while compiling and installing the source, it means you can continue and verify that the installation was successful. Execute the following command to print the version information of the binary you just compiled:
$ lighttpd -v
lighttpd-1.4.11 - a light and fast webserver Build-Date: May 14 2006 20:46:11
Weíll show you how to configure LightTPD after we install the other software.