How to install Tracks on Debian Lenny with Apache mod_fcgid

by Sander Marechal

I have recently read Getting Things Done (GTD) by David Allen. My geek life is the usual “too much to do in so little time” and I keep forgetting all kinds of important stuff. I saw a lot of FOSS sites covering GTD in the past few months so I decided to give it a go, read the book and play with all kinds of software. I quickly came across Tracks, a nice looking GTD application to manage your actions.

Unfortnately it's written in Ruby on Rails which can be a bit of a pain to set up under Linux, especially if you want to use Apache as the webserver instead of the built-in WEBrick server. I’m already running Apache on my server and I didn’t feel like running a second webserver on a different, non-standard port just for this one app. It took me quite a bit of time to piece it all together, but here’s how I set up Tracks in Debian Lenny.

Installing Ruby on Rails and mod_fcgid

Installing Ruby on Rails is the easy part. Starting with Debian Lenny it all comes prepackaged, so all we need to do is install a couple of packages from the repository.

  1. aptitude install rails rake ruby rdoc irb libapache-mod-fcgid libfcgi-ruby1.8 rubygems1.8 libmysql-ruby

The last two packages aren’t strictly necessary for Ruby on Rails, but they are dependencies for Tracks. If you are going to use sqlite as the database backend for Tracks, you can skip libmysql-ruby.

Installing and configuring Tracks

Now it gets a bit hairier. First off, none of the currently released versions of Tracks will work on Debian Lenny. There appears to be some conflict between Ruby 1.8.7 and both Tracks 1.5 and tracks 1.6. I have no idea if the problem is caused by Tracks, Ruby or the Debian packagers but it simply won’t work. You will get strange NoMethodError errors or simply a HTTP 500 server error. So, we will need to install the current development branch of Tracks instead.

You can download Tracks 1.7-devel from GitHub. Unpack it somewhere conveniently. In my example I will be installing Tracks to /var/www/tracks-devel. Installation is pretty much as described in the Tracks manual.

First copy log.tmpl, config/database.yml.tmpl and config/environment.rb.tmpl to the variants without the .tmpl extension. Then you can edit database.yml and environment.rb to suit your needs. If you are using a MySQL database then you will need to populate the new database with tables.

  1. rake db:migrate RAILS_ENV=production

Now it’s time to configure Apache and tell it to run Tracks using mod_fcgid. In the example below I will be running tracks in it's own virtual host on http://tracks.example.org, so change that to whatever meets your need. Start off with a basic virtual host configuration.

  1. <VirtualHost *:80>
  2.         DocumentRoot /var/www/tracks-devel/public
  3.         ServerName tracks.example.org
  4.         ServerSignature On
  5.  
  6.         LogLevel warn
  7.         ErrorLog /var/log/apache2/error.log
  8.         CustomLog /var/log/apache2/access.log combined
  9. </VirtualHost>

Now we add a handler for fcgi files and tell Apache to execute these with fcgid. We also add a RAILS_ENV environment variable to tell Tracks to execute in production mode instead of in development or test mode.

  1. AddHandler fcgid-script .fcgi
  2. DefaultInitEnv RAILS_ENV production
  3.  
  4. <Files *.fcgi>
  5.         SetHandler fcgid-script
  6.         Options ExecCGI +FollowSymLinks
  7. </Files>

Now we need a bit of mod_rewrite magic. In the current setup, not all the requests end up properly at the dispatch.fcgi script. We use a rewrite rule to rewrite all requests to dispatch.fcgi with the exception of requests for actually existing files. If we don’t add that exception then CSS sylesheets and javascript files cannot be loaded.

  1. <Directory /var/www/tracks-devel/public>
  2.         RewriteEngine on
  3.         RewriteCond %{REQUEST_FILENAME} !-f
  4.         RewriteRule ^/(.*) dispatch.fcgi [QSA,L]
  5. </Directory>

Now you can restart Apache and visit http://tracks.example.org/signup in order to create your Tracks admin account and start using it. Below is the full Apache configuration file. I hope this will help you to get things done!

  1. <VirtualHost *:80>
  2.         DocumentRoot /var/www/tracks-devel/public
  3.         ServerName tracks.example.org
  4.         ServerSignature On
  5.  
  6.         LogLevel warn
  7.         ErrorLog /var/log/apache2/error.log
  8.         CustomLog /var/log/apache2/access.log combined
  9.  
  10.         AddHandler fcgid-script .fcgi
  11.         DefaultInitEnv RAILS_ENV production
  12.  
  13.         <Files *.fcgi>
  14.                 SetHandler fcgid-script
  15.                 Options ExecCGI +FollowSymLinks
  16.         </Files>
  17.  
  18.         <Directory /var/www/tracks-head/public>
  19.                 RewriteEngine on
  20.                 RewriteCond %{REQUEST_FILENAME} !-f
  21.                 RewriteRule ^/(.*) dispatch.fcgi [QSA,L]
  22.         </Directory>
  23. </VirtualHost>
Creative Commons Attribution-ShareAlike

Comments

#1 Pratik (http://m.onkey.org)

You should really use mod_rails which makes it easy as pie to setup Rails app with Apache - http://www.modrails.com/

#2 Sander Marechal (http://www.jejik.com)

It sounds nice, but it does not appear to be packaged for Debian. Perhaps the Ubuntu version works though, but I'll have to test that.

#3 Brett (http://www.braineak.com/category/programming)

Yes you should really consider using mod rails instead...and ror is awesome...hardly a pain :-)

#4 Sander Marechal (http://www.jejik.com)

I have just found another reason *not* to use mod_rails a.k.a. Passenger: The Ubuntu packages requires apache2-mpm-worker, that is the threaded Apache2 server. PHP5 cannot work on the threaded apache server. It needs a forking Apache server such as apache2-mpm-prefork or apache2-mpm-itk. Using Passenger means that you cannot have Rails and PHP5 on the same server and Apache. With fcgid you can have both on the same server.

I'm a PHP developer. No way I am removing libapache2-mod-php5 from my servers :-) Perhaps it is possible to build Passenger from source against apache2-mpm-prefork, but I haven't tried that (yet).

#5 Anonymous Coward

sudo apt-get install gcc make;
sudo apt-get install zlib1g-dev;
sudo apt-get install build-essential;
sudo apt-get install git-core;
sudo apt-get install mysql-server mysql-client
sudo aptitude install libmysql++-dev libmysqlclient15-dev checkinstall
sudo apt-get install apache2-mpm-prefork
sudo apt-get install apache2-prefork-dev

wget http://www.openssl.org/source/openssl-0.9.8i.tar.gz
tar xzf openssl-0.9.8i.tar.gz
cd openssl-0.9.8i/
./config
make
sudo make install

cd

wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p286.tar.gz
tar xzf ruby-1.8.6-p286.tar.gz
cd ruby-1.8.6-p286
./configure --with-openssl-dir="/usr/local/ssl/"
make
sudo make install

cd

sudo apt-get install libopenssl-ruby;

wget http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz
tar zxf rubygems-1.3.0.tgz
cd rubygems-1.3.0
sudo ruby setup.rb

cd

wget http://www.sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz
tar xzf sphinx-0.9.8.1.tar.gz
cd sphinx-0.9.8.1
./configure
make
sudo make install

sudo gem install mysql
sudo gem install rails
sudo gem install capistrano
sudo gem install passenger
sudo passenger-install-apache2-module

==add to apache.conf==
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3
PassengerRuby /usr/local/bin/ruby

sudo /etc/init.d/apache2 restart

#6 Sander Marechal (http://www.jejik.com)

Thanks, I will try that.

#7 Chris

Thanks for the great how-to! I struggled for hours and hours with the normal releases and thought it was my ruby setup before stumbling on your guide that said its just a debian <-> tracks thing.

One thing I found was that your Vhost configuration (while more restrictive than mine thus more secure) didn't seem to like tracks on my server. I ended up going with a old trusty one. I suspect it had to do with the Options allow only happening on .fcgi maybe?

Anyway, nice work on the guide. Was a life saver :)

-Chris

#8 kaner (http://kaner.strace.org)

I got problems with the Javascript and CSS (despite the rewrite rule) on a recent Debian Lenny with Track 1.8 devel from the Git repository. Anyway, I got rid of it by adding the following line to the Apache config:

Alias /tracks /var/www/tracks-devel/public

HTH,
kaner

#9 Anonymous Coward

I'm getting this error on Debian Lenny, when using this tutorial:

1 root@box /var/gtd/tracks # RAILS_ENV=production rake db:migrate :(
(in /var/gtd/tracks)
rake aborted!
no such file to load -- spec/rake/spectask
/var/gtd/tracks/Rakefile:10
(See full trace by running task with --trace)
1 root@box /var/gtd/tracks #

#10 Sander Marechal (http://www.jejik.com)

That looks like a problem with Tracks instead of a problem with rails on fcgid. You may want to ask the Tracks developers about this.

#11 Robin Mitra (http://www.robinmitra.com)

Your installation guide makes it look so easy. I will have to try it out.

In the meantime, to the mod_rail users, what's the benefit of using mod_rail instead of mod_fcgid? How does the performance compare?

#12 Sander Marechal (http://www.jejik.com)

I have not tested mod_rails, but I imagine that the benefits are the same as mod_perl and mod_php: More speed. Mainly because libraries and resources can be cached instead of reloaded for each request. For mod_rails this should be quite a significant performance gain because Rails is slow to start.

#13 Robin Mitra (http://www.robinmitra.com)

Sander

I followed your guide and installed Tracks. I could open up the page to signup for an account on Tracks, but after that I get this error:
"Application error (Apache)
Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html"

Is this the error you mentioned near the top of the guide?

My version of Tracks is 1.7, as you suggested. Did you install version 1.7 or 1.7RC/RC2?

#14 Robin Mitra (http://www.robinmitra.com)

Just wanted to let you know, and for anyone might have the same problem, I solved the problem. After looking at the log, I realised that access was denied to certain things. So, I changed the owner of the tracks-devel directory by:

chown www-data:www-data -R /var/www/tracks-devel

Also, I noticed that uncommenting subdir:"/tracks" in site.yml and changing it to "/tracks-devel" (or even keeping it as "/tracks") caused problems accessing CSS files needed for styling page.

BTW, there is a typo in your article: <Directory /var/www/tracks-head/public> should be <Directory /var/www/tracks-devel/public>

Thanks alot for this tutorial, you saved me from relying on bitnami's stack install, which really was an overkill for just one application.

#15 Sander Marechal (http://www.jejik.com)

I'm happy to hear you managed to solve your problem. I've updated my article to fix the typo you pointed out. Thanks!

#16 Colin Mollenhour (http://colin.mollenhour.com)

Gem did not set proper permissions for me, so to fix I had to run:

sudo chmod -R a+rX /usr/lib/ruby

Comments have been retired for this article.