Rails Passenger Staging environment problem in Dreamhost

Problem
You want to deploy your rails application using Passenger in Dreamhost, but on a staging environment. It doesn’t work just changing your Capistrano recipe or your environment files, as the default environment for passenger is ‘production’.

Solution
Looking at the Passenger documentation here, there are four different ways of achieving that by changing the RailsEnv option. If you don’t want to change the Apache configuration files, and as long as the option AllowOverride is on (which should be on Dreamhost), then you would need to create an .htaccess file in your application’s public folder with the following:

RailsEnv staging

Dreamhost – SquirrelMail – old-messages folder

Problem
You have left a message in a squirrel mail account in dreamhost for a long time and it gets archived by dreamhost. According to the dreamhost you should be able to get to your archived messages, by looking at the old-messages folder.
The problem is that just by logging in to squirrel mail the folder doesn’t get displayed on the left hand side.

Solution
Log on to squirrel mail and go to ‘Folders’ menu at the top.
In the ‘Create Folder’ put ‘test’ or anything that you would like in the text box, and make sure that in the dropdown box you select ‘INBOX.old-messages’, so your newly created folder is a subfolder of the ‘inbox/old-messages’ folder.
Create the subfolder, refresh the page, and in your left hand the old-messages folder should appear.

Thunderbird – GoogleMail

Problem
You want to add the Google calendar tab in your thunderbird but you don’t want to use the standard google mail calendar, but the one setup for your domain.

Solution
Install the Google Calendar add on in Thunderbird:

Tools -> Addons -> Get Add-ons and then search for Calendar (Google Calendar Tab)

The when thunderbird is restarted go and change the default domain for logging in to the calender in:

Tools – Add-ons -> Extensions

and select the Preferences in the Google Calendar Tab.

from there select the ‘Google Apps for your domain’ and then change the URL into something like:

‘http://www.google.com/calendar/hosted/your_domain_hosted_with_google

406 Not Acceptable – Princely – Dreamhost

Problem
You get a ‘406 Not Acceptable’ response from the web server when you try to use the princely plugin for generating pdf on a Ruby on Rails application hosted on dreamhost.

Solution
Having tried the ‘Extra Web Security’ settings in dreamhost Web panel, and setting them on/off did not get very far.
Also setting up an .htaccess file didn’t seem to make any difference.
So the mod_security settings did not seem to be the cause of the problem.
Having a look at the apache error log files which in the case of the dreamhost ps are in /usr/local/dh/apache2/logs/apache2-ps_name it turns out that the problem was that the path for the prince binary was not setting up correctly in the file vendor/plugins/princely/lib/prince.rb on line 26.
A quick hack to make it work until finding the reason for the problem is to hardcode the path to the prince binary, so:
@exe_path = `which prince`.chomp
if @exe_path.nil?
@exe_path=’/usr/local/bin/prince’
end

undefined method ‘remap’ for class ‘Magick::Image’

Problem
You have just deployed your rails application to dreamhost but you are getting this error from passenger.

Solution
There was a change in the ImageMagic between versions 6.4.3 and 6.4.4 from the affinity function to remap.
If you don’t want, or don’t have time to recompile the ImageMagick and install the rmagick gem, you can comment out the two declarations for the alias functions, located around lines 782 and 1525 in the file rmagick-2.12.2/lib/RMagick.rb:

alias_method :affinity, :remap

Freezing rails to an older version using gems

Problem
You want to deploy to a shared host (dreamhost) that has a later version of rails from the one you have developed your application.
You also have a later version installed in your development pc,and using rake rails:freeze:gems uses the latest one and not the one you want.

Solution
Use the following to freeze the specific version you want, and by using your gems you have installed:
rake rails:freeze:gems VERSION=2.3.2

Getting your Github git project to dreamhost

Problem
You already have a project in github, but you want to move it to a different host (ie dreamhost)

Solution
Following the post here that describes how to setup a new git repository in dreamhost, the only difference after the initial setup :

ssh username@dreamhost_domain.com

mkdir -p ~/git/yourproject.git

cd ~/git/yourproject.git

git --bare init

is to edit your project’s .git/config file:
vi local_host/your_project/.git/config

and change the :
url = git@github.com:user_name/project_name.git

to the following:
ssh://dreamhost_username@dreamhost_domain/~/git/yourproject.git

Lastly you have to push for the first time to the server:
git push origin master

Optionally if you would like to check and/or checkout to a different pc you can use:
git clone ssh://dreamhost_username@dreamhost_domain/~/git/yourproject.git

RubyGem version error: rack(0.3.0 not ~> 1.0.0)

Problem
Trying to deploy in dreamhost with capistrano you get the error:

RubyGem version error: rack(0.3.0 not ~> 1.0.0)

Solution
Log in with ssh to your dreamhost account and then install the newer version of rack that is not yet installed in dreamhost:

gem install rack

That assumes that you have followed the instructions for setting up your local gems in dreamhost (here) and you already have a ~/username/.gems directory.

You may probably need to also add the following to your config/environment.rb :

ENV[‘GEM_PATH’] = ‘/home/USERNAME/.gems’

Note 09-Sep-2009
It seems that according to the dreamhost wiki we need to add the following to the config/environment.rb, instead of the line above:

if ENV[‘RAILS_ENV’] == ‘production’
ENV[‘GEM_PATH’] = ‘/home/USERNAME/.gems’
require ‘/home/USERNAME/.gems/gems/rack-1.0.0/lib/rack.rb’
end

to use the locally installed rack-1.0.0 gem, instead of the rack installed by dreamhost.

Dreamhost, Rails 2.1.1, Freeze, Capistrano

Problem
With the imminent upgrade in Dreamhost to Rails 2.1.1 (dreamhost blog post here), you may want to freeze your Rails version to a previous version, using capistrano.

Solution
On your local development pc freeze the rails:

rake rails:freeze:gems

Add the new code to your svn repository:

svn commit -m 'freeze rails'

And then deploy to dreamhost using capistrano:

cap deploy

Your rails project located on dreamhost should be frozen to your current Rails version.

Developing in Rails 2.1 and deploying in Rails 2.0.2 (or error – undefined method time_zone)

Problem
You are developing on the latest version of Rails (2.1), but your production server for deployment uses version 2.0.2 (as dreamhost is using at the moment).

Solution

  1. First change the environment.rb file to use the rails version in your deployment server
    RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
    
  2. You should probably be geting the error: undefined method = time zone by now, so make sure you comment out from further down your environment.rb file the line:
    config.time_zone = 'UTC'
  3. Some further errors would be caused by the file config/initializers/new_rails_defaults.rb, so make sure you comment out the following lines:
    ActiveRecord::Base.include_root_in_json = true
    ActiveRecord::Base.store_full_sti_class = true
    ActiveSupport.use_standard_json_time_format = true
    ActiveSupport.use_standard_json_time_format = true

You should be able to deploy and use your application now.