Make Poverty History - 2005 - Abolissons la pauvreté
Paying the bills with my mad programming skills...
Today | RSS | RDF | Atom | Other


One of the first things I'm trying to get going in 2007 is a way to be more productive while at the same time not losing my mind with all the stuff I have to do, which is the mental state that I'm in right now. I just finished reading a fantastic book on the subject, Getting Things Done, and have decided to get started with it. One of the key concepts of the approach is to have a place where all your projects and tasks are stored, and for me, it makes sense that that place be an electronic one.

I tried getting the GTD template for Lotus Notes going since I use Lotus Notes at work, but it didn't work out for me since I'm using a pre-Beta of the next version of Notes, Hannover, and I'm experiencing unrelated problems at the moment. I did some searching and found an application called Tracks that also might be able to help me out. I thought it was interesting because I had heard about it before and it was also based on Ruby on Rails, the so-called latest and greatest web development platform.

As it turns out, my first experience with Ruby on Rails has been pretty much brutal. As with all things geek-related, it's hard to install and use. Below what I did to get it going on my Fedora Core 4 web server, but VMMV. For the record, this document assumes you already have Apache and MySQL installed and running.

  1. Get Tracks and prepare it and your database

    I started with the installation manual and tried following the steps. First, download Tracks and unzip it where you want it to be stored. In my case, I'm keeping it in /srv.

    [root@eloise]# cd /srv
    [root@eloise srv]# wget http://www.rousette.org.uk/projects/files/tracks-1.043.zip
    [root@eloise public]# unzip tracks-1.043.zip 
    
    I like to make the whole folder owned by the webserver:
    [root@eloise srv]# chown -Rf apache:apache tracks-1.043
    
    Next, get your database set up.
    [root@eloise srv]#mysql -u root -p
        mysql> CREATE DATABASE tracks104;
        mysql> GRANT ALL PRIVILEGES ON tracks104.* TO yourmysqluser@localhost \
         IDENTIFIED BY 'password-goes-here' WITH GRANT OPTION;
    
    Copy the file config/database.yml.tmpl to config/database.yml, config/environment.rb.tmpl to config/environment.rb and log.tmpl to log.
    [root@eloise srv]# cd /srv/tracks-1.043/config
    [root@eloise config]# cp database.yml.tmpl database.yml 
    [root@eloise config]# cp environment.rb.tmpl environment.rb 
    [root@eloise config]# cd .. 
    [root@eloise tracks-1.043]# cp -rf log.tmpl log 
    
    Open the config/database.yml file, and enter your username and password details for the database you just set up under the 'production' and 'development' sections.
    [root@eloise tracks-1.043]# vi config/database.yml 
    
    Open the file config/environment.rb and look at the last line which should read: SALT = "change-me". Change the word change-me to something else of your choosing.
    [root@eloise tracks-1.043]# vi config/environment.rb 
    
    It's at this point that the default instructions pretty much fall apart for us Fedora Core users.

  2. Install Ruby and put it on Rails

    I found a great part of the well-written guide Installing Ruby on Rails with Lighttpd and MySQL on Fedora Core 4 that really helped me out. A lot of the steps below are based on it, except I am using Apache and not Lighttpd.

    First, install the necessary libraries:

    [root@eloise]# yum install ruby ruby-libs ruby-devel irb rdoc
    
    Looks simple, doesn't it? Well ... surprise! It's not! Now you have to download the "Ruby" platform installer and do a bunch of stuff from there:
    root@eloise]# cd /tmp
    root@eloise tmp]# wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
    [root@eloise tmp]# tar -zxvf rubygems-0.9.0.tgz
    [root@eloise tmp]# cd rubygems-0.9.0
    [root@eloise rubygems-0.9.0]# ruby setup.rb
    
    You should see a message like this:
     Successfully built RubyGem
    
    Now you can clean up and install Rails:
    [root@eloise rubygems-0.9.0]# cd ..
    [root@eloise tmp]# rm ruby* -drf
    [root@eloise tmp]# gem install rails --include-dependencies
    
    You should receive a message indicating that rails has been installed successfully.

  3. Set up Tracks

    Here's where we continue with the installation manual. It says to execute the following command in your tracks installation folder:

    [root@eloise tracks-1.043]# rake migrate
    
    Unfortunately for us, it's probably going to fail with a message similar to this:
    No such file or directory - /tmp/mysql.sock
    
    I had a look at the Debian installation guide and it had the fix there. What you need to go is edit the database.yml file again and add a reference for the MySQL socket file, which is in a different location in Fedora.
    [root@eloise tracks-1.043]# vi config/database.yml 
    
    What you want to do is add a "socket" line as follows for your development and production environments:
    development:
      adapter: mysql
      database: tracks104
      host: localhost
      username: yourdbusername
      password: yourdbpassword
      socket: '/var/lib/mysql/mysql.sock'
    
    production:
      adapter: mysql
      database: tracks104
      host: localhost
      username: yourdbusername
      password: yourdbpassword
      socket: '/var/lib/mysql/mysql.sock'
    
    Then, you can execute the migrate command again:
    [root@eloise tracks-1.043]# rake migrate
    
    Unfortunately (again), it's probably going to fail with a different error message:
    [root@eloise tracks-1.043]# rake migrate
    (in /srv/tracks-1.043)
    rake aborted!
    Mysql::Error: Lost connection to MySQL server during query: SELECT version FROM schema_info
    
    (See full trace by running task with --trace)
    
    Now, I'm not sure what I did to resolve this, but I think the basic thing was that there is some kind of version compatibility in the way MySQL stores privileges or passwords because of an upgrade I did in the past or something. I did a few things to get it going. First, I edited the /etc/my.cnf file and changed the old_passwords line:
    [root@eloise tracks-1.043]# vi /etc/my.cnf
    
    I commented out the previous line and created a new one with a different value:
    #old_passwords=1
    old_passwords=0
    
    That didn't seem to work so I tried to flush the privileges:
    [root@eloise tracks-1.043]# mysql -u root -p
        mysql> flush privileges;
        mysql> exit
    
    That didn't seem to work either so I executed a script that tries to resolve the problem:
    [root@eloise tracks-1.043]# mysql_fix_privilege_tables --password=yourdbpassword
    
    I restarted:
    [root@eloise tracks-1.043]# /sbin/service mysqld restart
    Stopping MySQL:                                            [  OK  ]
    Starting MySQL:                                            [  OK  ]
    
    Now I decided to overwrite the password for my database user just to make sure it was stored correctly:
    [root@eloise tracks-1.043]# mysql -u root -p
        mysql> SET PASSWORD for tracks@localhost=PASSWORD('yourdbpassword');
        mysql> exit
    
    I restarted and ran the script again, this time it seemed to work:
    [root@eloise tracks-1.043]# /sbin/service mysqld restart
    Stopping MySQL:                                            [  OK  ]
    Starting MySQL:                                            [  OK  ]
    [root@eloise tracks-1.043]# rake migrate
    

  4. Set up Apache

    To get it going in Apache, the easiest way is to create your own app-specific configuration file:

    [root@eloise tracks-1.043]# vi /etc/httpd/conf.d/tracks.conf
    
    Populate it as follows:
    Alias /youraliasname/ "/srv/tracks-1.043/public/"
    <Directory /srv/tracks-1.043/public/>
          Options ExecCGI FollowSymLinks
          AllowOverride all
          Allow from all
          Order allow,deny
    </Directory>
    
    You will notice that I used an alias because that's just how I roll. If you use an alias, you will have to modify the .htaccess file accordingly.
    [root@eloise tracks-1.043]# vi public/.htaccess
    
    Add this line around where the comments tell you to:
    RewriteBase /youraliasname
    

    The application should now be available for you to access at http://yourservername/youraliasname. That doesn't mean you can use it, though, 'cause it will probably be horribly slow!

    To try to fix this, you can change the environment to "production". By default, it's set to "development" which has a bunch of debugging stuff on that you don't need. To change it, edit the environment.db file:

    [root@eloise tracks-1.043]# vi config/environment.rb 
    
    Change the environment by changing the line as follows:
    ENV['RAILS_ENV'] = 'production'
    

    Now that you've tried again, you'll probably notice that it's still super slow. In that case, there's even more work to be done!

  5. Improve performance (slightly) with FastCGI

    First, you need to install the FastCGI development libraries and the Ruby FastCGI bindings.

    [root@eloise tracks-1.043]# cd /tmp
    [root@eloise tmp]# wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz 
    [root@eloise tmp]# tar -zxvf fcgi-2.4.0.tar.gz 
    [root@eloise tmp]# cd fcgi-2.4.0 
    [root@eloise fcgi-2.4.0]# ./configure 
    [root@eloise fcgi-2.4.0]# make 
    [root@eloise fcgi-2.4.0]# make install 
    [root@eloise fcgi-2.4.0]# cd ..
    [root@eloise tmp]# rm fcgi* -drf
    
    [root@eloise tmp]# wget http://sugi.nemui.org/pub/ruby/fcgi/ruby-fcgi-0.8.6.tar.gz
    [root@eloise tmp]# tar -zxvf ruby-fcgi-0.8.6.tar.gz 
    [root@eloise tmp]# cd ruby-fcgi-0.8.6 
    [root@eloise ruby-fcgi-0.8.6]# ruby install.rb config 
    [root@eloise ruby-fcgi-0.8.6]# ruby install.rb setup 
    [root@eloise ruby-fcgi-0.8.6]# ruby install.rb install 
    [root@eloise ruby-fcgi-0.8.6]# cd .. 
    [root@eloise tmp]# rm ruby-fcgi-0.8.6* -drf
    

    Now you need to get it going with Apache. I found a guide called Red Hat Enterprise Linux 4 + RT 3.4.2 + FastCGI 2.4.2 Install Guide that helped me get through figuring out how to install this. In order to compile the needed Apache module, you have to download the Apache development kit:

    [root@eloise public]# yum install httpd-devel
    
    Then, download and extract the module source:
    [root@eloise tmp]# wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
    [root@eloise tmp]# tar -xzvf mod_fastcgi-2.4.2.tar.gz
    
    You'll need to edit some files before you can compile.
    [root@eloise tmp]# cd mod_fastcgi-2.4.2
    [root@eloise mod_fastcgi-2.4.2]# cp Makefile.AP2 Makefile
    [root@eloise mod_fastcgi-2.4.2]# vi Makefile
    
    Change this line as follows to match up with the Fedora environment:
    top_dir      = /etc/httpd
    
    Then you can compile, install, and clean up:
    [root@eloise mod_fastcgi-2.4.2]# make
    [root@eloise mod_fastcgi-2.4.2]# make install
    [root@eloise mod_fastcgi-2.4.2]# cd ..
    [root@eloise tmp]# rm mod_fastcgi* -drf
    
    You need to make some directories available to the module for it to use:
    [root@eloise tmp]# mkdir /etc/httpd/logs/fastcgi
    [root@eloise tmp]# mkdir /etc/httpd/logs/fastcgi/dynamic
    [root@eloise tmp]# chown apache:apache /etc/httpd/logs/fastcgi
    [root@eloise tmp]# chown apache:apache /etc/httpd/logs/fastcgi/dynamic
    
    Now you need to set up the app to use FastCGI. First, edit .htaccess again:
    [root@eloise tmp]# vi /srv/tracks-1.043/public/.htaccess
    
    Comment out the existing line below and add your own to point to the dispatch.fcgi file:
    #RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    
    Now, edit your tracks.conf file:
    [root@eloise tmp]# vi /etc/httpd/conf.d/tracks.conf
    
    You need to add a line to the top and to the bottom so the file reads as follows:
    LoadModule fastcgi_module modules/mod_fastcgi.so
    Alias /youraliasname/ "/srv/tracks-1.043/public/"
    
          Options ExecCGI FollowSymLinks
          AllowOverride all
          Allow from all
          Order allow,deny
    
    FastCgiIpcDir /tmp
    
    Restart the server:
    [root@eloise public]# /sbin/service httpd restart
    
    The restart will probably fail with an error like this:
    FastCgiIpcDir /tmp: can't create dynamic directory "/tmp/dynamic": access for se
    rver (uid -1, gid -1) failed: read not allowed
    
    I found a bunch of info on this page that helped. You'll need to make a directory that FastCGI just created accessible to it:
    [root@eloise public]# chmod 777 dynamic
    
    Now, restart Apache and you should be set!
    [root@eloise public]# /sbin/service httpd restart
    

You now have a fully functioning installation of Tracks that is somewhat fast but probably feels sluggish. You've also just wasted a couple hours of your time. The steps involved to get this going just amazed me. If anyone has any suggestions on a better way to do it, please let me know! What a huge pain in the ass!