Adding Rails/Passenger to Debian Using Ruby Gems

I needed to serve both static and Ruby on Rails (RoR) pages on my rubyat.com site running Debian gnu/Linux stable (lenny). The apt-get/Debian way is unsatisfactory, as, among other issues, Debian does not yet have Passenger in its stable (lenny) branch. After doing some research, and some trial and error, this is what worked for me.

1. Uninstall any gems. I’d installed  rake and Rails via Debian apt-get. Unfortunately, most Ruby gems aren’t available that way.

2. Uninstall rubygems via apt-get. Same logic.

3. Install ruby development headers.
sudo apt-get install ruby1.8-dev

4. Install rubygems from source. This gets me the newest version of rubygems, and also makes all future gems available.

sudo wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
sudo tar -xzvf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb

5. Install Rails.
sudo gem install rails (Installs the latest stable version of Rails. Today it is 2.3.8).

6. Install Passenger.
6a. Install the Passenger Ruby Gem.
sudo gem install passenger

6b. Install the Apache Passenger module.
sudo apt-get install apache2-prefork-dev
sudo apt-get install libapr1-dev (Note: already installed on my machine.)
sudo apt-get install libaprutil1-dev (Note: already installed on my machine.)
sudo passenger-install-apache2-module

6c. Edit my Apache configuration file. In Debian, this is /etc/apache2/apache2.conf.
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.15
PassengerRuby /usr/bin/ruby1.8

Now, some of my web sites use an older version of rails. So:

7. Install older version of rails.
sudo gem install -v=2.1.0 rails

8. Restart Apache.
sudo /etc/init.d/apache2 restart

At this point, Ruby on Rails pages get served, but other content (such as this WordPress blog) does not.

9a. Edit my site Apache configuration.
sudo nano /etc/apache2/sites-available/mysite
inside <VirtualHost> add the following three lines:
<Location /blog>
PassengerEnabled off
</Location>

And these three lines:
<Location /mail>
PassengerEnabled off
</Location>

9b. Restart Apache.
sudo /etc/init.d/apache2 restart

9c. Test the configuration. Make sure everything works. For me, it does.

Rails 2.3.8 - Segmentation Fault

I just upgraded to Rails 2.3.8 on my development machine. I created a standard Rails app, started up WEBrick, and got a Segmentation fault. Not enough code to be my error, so I searched for the core problem and possible solutions.

Turns out the issue is known, and a solution exists. First, I updated to the latest version of Ruby 1.8.6. Not 1.8.7, and certainly not 1.9.2. Too many people reported unresolved problems with Ruby 1.8.7, and Ruby 1.9.2 hasn’t yet gone stable. As of 16 June 2010, the latest version available as an exe for Windows is ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32].

Next, did a gem install rails (version 2.3.8). Third, a gem install mysql (2.8.1 x86-mingw32). This gave errors for the documentation, but the gem installs.

Finally, I copied libmySQL.dll (1484 KB) from http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll as recommended at http://forums.aptana.com/viewtopic.php?f=20&t=7563&p=27407&hilit=libmysql.dll#p27407 . After that, everything just works.

Rails 3.0.0.beta install

Installed Rails 3.0.0.beta on my test machine. Here’s a few notes on what was easy, what was not.

My test machine uses Debian squeeze (testing), ruby 1.9.1 and rubygems 1.3.5. You need to have ruby 1.8.7 or newer. Ruby 1.8.6 will not work.

To find out what version of ruby you have, enter: ruby -v.

For a full rubygems environment listing, enter: gem env

To find out what paths ruby is looking for, enter: irb

followed by: puts $LOAD_PATH

My first attempt in installing Rails 3 failed, with this error message:

sudo gem install rails –pre
ERROR:  Error installing rails:
actionpack requires rack-mount (~> 0.4.0, runtime)

So, I get to go a bit deeper:

sudo gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
sudo gem install rack-mount –version 0.4.0
sudo gem install rails –pre

But this isn’t enough to create a new project. So:

sudo gem install abstract
rails rubyat.com -d mysql

Now, there’s still more to be done in order to use rails console:

sudo apt-get install libmysql-ruby1.9
sudo apt-get install libmysqlclient-dev
sudo gem install mysql — –with-mysql-dir=/usr/bin –with-mysql-lib=/usr/lib/mysql
sudo gem install mime-types
sudo gem install text-hyphen

Finally, enter: rails console and we have the familiar irb console.

SquirrelMail – change_sqlpass plugin

Found a bug in the squirrelmail change_sqlpass plugin. Made the ugly fix; gonna dive in and write a patch later.

The bug occurs in functions.php

There is a mismatch between:
function get_password_salt, where the program reasonably returns the value of the password salt when $csp_salt_static is empty and $csp_salt_query is not empty.

and:
function get_password_encrypt_string, in the switch statement,
it uses the value of the password salt as the name of the password salt field, and the SQL fails.

It’s a one line fix:
- return ‘encrypt(“‘ . $password . ‘”, ‘ . $salt . ‘)’;
+ return ‘encrypt(“‘ . $password . ‘”, “‘ . $salt . ‘”)’;

Rubyat.com

Just finishing setting up four web sites, including rubyat.com.