Fabian is proud to present you this little tip:

Nitro with FastCGI on Apache2

Written by Michael Fellinger, prepared for Oxyliquit by Fabian Buch

This is the first draft for doing an installation of Nitro on Apache 2. I am using an Ubuntu system; these intructions should work well with any Debian-based distro. I’m running Nitro on a virtual host; running in a different configuration may work a bit differently. I will document some other variations later on.

I am doing this as I go through the installation, documenting as I go. This configuration works for me, but as always, your mileage may vary.

Notes for distros:

Ubuntu:

  • based on latest breezy (5.10).

Debian:

  • you can do ‘su’ and enter the password of root and continue to do the stuff described here whenever you see sudo. Just don’t forget to ‘exit’ when you are done.

Now, let’s get apache moving…

manveru@lambda:~$ sudo apt-get install apache2
.... long text ....

Since CGI is too slow, also install FastCGI:

$ sudo apt-get install libapache2-mod-fcgid
.. more text ..
$ sudo gem install fcgi
.. ..

Configuration

The configuration of Apachw2 is a bit different depending on what distribution you use. What generally has to be done: load FastCGI and making a VirtualHost.

httpd.conf

Put this at the end of your your httpd.conf which usually resides in /etc/apache2/

LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so

# Important. The following directives come *after*
# User and Group
FastCgiIpcDir /var/tmp/fcgi
FastCgiConfig -initial-env 'RUBYOPT=-rubygems'

AddHandler fastcgi-script fcgi fpl rb

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName nitro
  DocumentRoot /path/to/app/public
 ErrorLog /path/to/app/log/apache.log

  ErrorDocument 500 "<h2>Application error</h2>Nitro failed to start properly" 

  <Directory "/path/to/app/public">
      Options FollowSymLinks  ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
  </Directory>

</VirtualHost>

You can configure your FastCGI environment to fit your Computer/Environment. This is what I have as my FastCgiConfig, since my computer is slow and can’t handle the starting 5 and up to 50 concurrently spawned nitro processes at once. Also if you don’t use rubygems for Nitro (maybe because of Glycerin) you can handle it like George did in his apache.conf file.

FastCgiConfig -initial-env 'RUBYOPT=-rubygems' -init-start-delay 10 -maxClassProcesses 2 -maxProcesses 2 -minProcesses 1 -pass-header Authorization -processSlack 1
  .. or ..
FastCgiConfig -initial-env 'RUBYOPT=-rubygems -I/home/gmosx/navel/nitro/lib -I/home/gmosx/navel/og/lib -I/home/gmosx/navel/glue/lib'

.htaccess

Next is a .htaccess file in your public/ folder.

RewriteEngine On
RewriteRule ^/$ /index.html [QSA]
RewriteRule ^([^.] )$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /fcgi.rb [QSA,L]

Remember to restart your apache using "apache2ctl graceful" and check your hosts file that the VirtualHost you just created in your httpd.conf actually exists. I chose "nitro" as an example.

hosts for this example

$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1             localhost
255.255.255.255 broadcasthost
::1                   localhost 
127.0.0.1             nitro

When you now browse to http://nitro/index, Apache loads Nitro, which might take a few seconds. Now pray to god that this works, and you’re set :D

Logs

You might want to observe the /path/to/app/log/apache.log file using "tail -f /path/to/app/log/apache.log".

Note

Have a look at Question 18 too. Make sure the user Apache runs on (www-data or apache, depending on your system) has the rights to execute your fcgi.rb.