Merb

From DreamHost
Revision as of 12:23, 23 April 2009 by Stanley (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
The instructions provided in this article or section are considered advanced.

You are expected to be knowledgeable in the UNIX shell.
Support for these instructions is not available from DreamHost tech support.
Server changes may cause this to break. Be prepared to troubleshoot this yourself if this happens.
We seriously aren't kidding about this.

Introduction

Merb is a web application framework written in the Ruby programming language.

These instructions describe how to get Merb running on a shared Dreamhost account using Passenger. These instructions assume you've set up a new domain with conventional (static HTML) web hosting and have not yet installed Rails, Merb, or switched on Passenger.

If you edit or update this wiki entry, please be sure to indicate which version of Merb you are using, as installation procedures may change with newer versions.

Overview

Merb 1.0 was released on November 7, 2008.[1]

Merb was originally conceived as an alternative to Ruby on Rails and improves on many aspects of Rails 2.0. As of December 23, 2008, the Merb project has begun to be merged with Rails, and a version with the best features of both will be released in late 2009 under the name Rails 3.0.[2][3]

Merb is considerably more efficient (and thus faster) than Rails and, combined with the stability and speed improvements obtained with Passenger, provides many of the development advantages of Rails with greater speed and stability in a shared hosting envvironment such as DreamHost.

More information about Merb can be found at the Merb community web site: Merbivore.

Before you begin

Merb 1.0 requires Ruby 1.8.6 or newer and RubyGems version 1.3.1 or newer.

Checking Your Ruby Version

Use ssh to log into your DreamHost shell account. At the prompt, type:

ruby -v

You should see "ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]" or something similar.

Checking Your RubyGems Version

Use ssh to log into your DreamHost shell account. At the prompt, type:

gem -v

You should see "1.3.1" or greater.

Upgrading Your DreamHost Server

If you have a new account at DreamHost, you'll likely have everything you need to install Merb. If your account at DreamHost was created before October 2008, you are likely on an older server (perhaps a "Debian Sarge" machine) that has an older version of Ruby.

If your version of Ruby is older than 1.8.7, go to your DreamHost account control panel and look for the link "UPGRADE TO UNLIMITED DISK AND BANDWIDTH FREE". This is an offer to move your hosting to a newer "Debian Etch" server which will provide Ruby 1.8.7.

You may want to make a request to DreamHost support asking to prioritize your server move. Explain that you need to install Merb which requires Ruby 1.8.7. If your request is prioritized, you may be moved to a new server within one or two days.

Installing Merb 1.0.7

Merb is currently at version 1.0.7 (December 29, 2008).

Create a "gems" Directory

Use ssh to log into your DreamHost shell account.

Merb gets installed as a RubyGem ("gem").

If you don't already have a gems directory, create a directory to store RubyGems in your home directory.

mkdir .gems

Set Your Environment Path

Modify your .bashrc file to configure your UNIX environment settings to include the .gem directory. Use vi or your favorite terminal editor to modify the .bashrc file. Or download, modify locally with a text editor, and upload the .bashrc file. See Nate Clark's post DreamHost Your Own Packages and Gems for details.

export PATH="$HOME/.gems/bin:${PATH}" 
export GEM_HOME=$HOME/.gems
export GEM_PATH="$GEM_HOME" 

Install Merb

Merb is not difficult to install. From your shell account, install the Merb gem.

gem install merb

Create a Merb App

Create an initial app to test the installation.

merb-gen app mymerbtest

Configure for "Rails"

on https://panel.dreamhost.com/ , twiddle:

  • Domains -> Manage Domains -> Edit (web hosting column)
  • Enable “Ruby on Rails Passenger (mod_rails)”
  • Add the public directory to the web directory box. So if you were using “gittr.com”, it would change to “gittr.com/public”

Add the config.ru File

With Merb 1.0.7, a generated Merb app is configured by default to run with the Mongrel web server. DreamHost is using Passenger (with Apache). To run a Merb app using Passenger, you need to add a config.ru file to the root directory of the Merb app.

The config.ru file can be complex. Here is a simple version:

# config.ru
# This is a simple config.ru file for running a Merb app with Passenger at DreamHost
# It should be installed in the root directory of your Merb app
# It has been tested with Merb 1.0.7 and Ruby 1.8.7
 
ENV['GEM_PATH'] = '/home/username/.gems/' # your local gem home
 
require 'rubygems'
require 'merb-core'
 
Merb::Config.setup(:merb_root => ".",
                   :environment => ENV['RACK_ENV'])
Merb.environment = Merb::Config[:environment]
Merb.root = Merb::Config[:merb_root]
Merb::BootLoader.run
 
run Merb::Rack::Application.new

Remove the merb.fcgi and .htaccess files

Removed the file named merb.fcgi from the "public" directory of the Merb app. With this file gone, you should have no error messages in the error log (see "Troubleshooting").

The /public/.htaccess file will route everything to /public/merb.fcgi by default, so delete the .htaccess file as well.

Switch to Passenger

These instructions assume you've set up a new domain with conventional (static HTML) web hosting and are not yet using Passenger with your web server. If you've already set up web hosting for a domain with Rails and Passenger, this section will not apply (however, you may need to change your configuration to point Passenger at your new Merb app).

If your domain is set up for conventional (static HTML) hosting, the document root or "web directory" (the place where HTML files belong) is a subdirectory in your home directory. By default, the directory has the same name as your domain. When you switch to Passenger, you'll specify your Merb app as your "web directory."

Go to the "Manage Domains" section of your DreamHost account control panel to edit the settings for your domain. Click the checkbox for "Ruby on Rails Passenger" and specify the "web directory" as /home/username/mymerbtest/public. Then change the "fully hosted" settings.

Note that you must install Merb and generate a Merb app before you configure your domain hosting to use "Ruby on Rails Passenger". Otherwise you will not have a Merb app available as your "web directory" when you switch to Passenger. The account control panel can be confusing because you want to use Passenger to run Merb, not Rails. And you're pointing Passenger at the web directory for a Merb app, not a Rails app. And furthermore, you might have expected to set up hosting with Passenger before installing Merb and creating a Merb app.

Start Merb

Merb must be running for Passenger to serve its web pages. From your DreamHost shell account:

cd mymerbtest
merb

Test

With your web browser, visit your site. You should see tbe default Merb "welcome" page.

Troubleshooting

Check the Error Log

By default, error messages will appear in the file:

/home/username/logs/yourdomain.com/http/error.log

Remove the merb.fcgi File

You may see the following in your error log:

 FastCGI: comm with (dynamic) server "/home/username/mymerbtest/public/merb.fcgi" aborted

Remove the .htaccess File

You may see the following in your error log:

 (2)No such file or directory: FastCGI: stat() of "/home/username/merb-app/public/merb.fcgi" failed

Missing config.ru File

Check to make sure you have a config.ru file in your Merb app directory.

"FATAL: Mongrel is not installed, but you are trying to use it. You need to either install mongrel or a different Ruby web server, like thin."

If you encounter this problem, first make sure that mod_rails is enabled, and then attempt to access your application with your web browser. You should see a Phusion/Passenger error page. Take important note of the ERROR messages on the page. In my case, Passenger on Dreamhost (w/ Merb 1.0.9 as of February 2009) complained that my directory didn't contain a ./log/production.txt file. I created a log directory, reloaded, and merb started up.

Keep in mind that I didn't have to actually run merb -- when you access your site, Passenger seems to automagically start up your merb application by itself (if it's not already running).

Comments

Merb does not run "out of the box" at DreamHost. It requires some typical UNIX configuration overhead (creating a ~/.gems directory and modifying the ~/.bashrc file). Second, Merb is configured by default for the Mongrel web server, not Apache and Passenger. Future versions of Merb may accommodate Passenger by default (see the currently open Lighthouse ticket) in which case installation may become a bit easier.

Hopefully this wiki entry makes Merb installation easier at DreamHost. Please do your part and add updates or clarifications that may help. You can make suggestions or introduce questions on the discussion page for this wiki entry.

Additional Resources

A blog entry at RubyInside on November 8th, 2008 lists 44 Links and Resources To Get You Going with Merb.

Getting Help

For help with Merb installation at DreamHost, you can try the DreamHost Community Forums.

The Google Group for Merb is a good source of general help: Merb Google Group.

There is an active IRC channel for Merb (#merb on irc.freenode.net). If you want to chat live about Merb but aren't familiar with IRC, see the Wikipedia entry on Internet Relay Chat.