Tuesday, August 11, 2009

Create a Rails Application on Dreamhost

  1. In the Dreamhost Web Panel, panel.dreamhost.com:

    1. Create demo.mikedll.com. Wait until the domain name is resolvable.

    2. In the host configuration, check "Enable FastCGI" and serve documents from /home/myusername/demo.mikedll.com/public.

  2. SSH into the web server and run:

    # Create the app
    rails demo.mikedll.com
    
    
    # Go into the public directory
    cd demo.mikedll.com/public
    
    
    # Recurisvely add world-executable to directories
    find . -type d -exec chmod o+x {} \;
    
    
    # Recursively add world-readable to files
    find . ! \( -type l \) ! \( -type d \) -exec chmod o+r {} \;
    
  3. In the root of the application directory, run:

    # Make dynamic-content
    ./script/generate controller demo index`.
    
    
    # Initialize the sqlite database
    rake db:migrate
    
  4. Create demo.mikedll.com/public/.htaccess with:

    # Launch dispatch.fcgi on requests for which
    # there is no static file
    AddHandler fastcgi-script fcgi
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    
  5. Remove demo.mikedll.com/public/index.html.

  6. Done

Expect visits to demo.mikedll.com to display static content.

Expect visits to demo.mikedll.com/demo to display dynamic content.

Pitfalls

  • This Apache error:

    [...] [error] [client ...] File does not exist: ... demo.mikedll.com/public/missing.html
    

    occurs if the .htaccess file is omitted.

  • Recent changes in the application code are not visible if an already-running instance of the application is not killed with killall dispatch.fcgi.

  • This Apache error:

    [...] [error] [client ...] FastCGI: comm with (dynamic) server ".../current/public/dispatch.fcgi" aborted: (first read) idle timeout (60 sec)
    [...] [error] [client ...] FastCGI: incomplete headers (0 bytes) received from server ".../current/public/dispatch.fcgi"
    

    occurs when then application crashes while loading. For example, I get this error when my config/environment.rb has a bug in it. The browser will hang for 60 seconds before the server responds with a terse, generic, rails error.

    To debug such issues, I run ./dispatch.fcgi at the command line. No arguments are required. Usually dispatch.fcgi will crashe, give an informative error, and provide faster debugging feedback.

Similar Work

More Trouble-shooting help is available in the Dreamhost "Rails Wiki".

Another guide on a Dreamhost/Rails/Radiant deployment features an application that has many users. It goes into more depth and draws on more experience.

My guide builds on another guide published early this year. This guide had some screenshots and clear directions. However, the .htaccess file in that guide doesn't serve static content, which was a problem for me. Someone else had the same problem. While solving this problem, I used sample .htaccess files at The Rails Playground and this Snipplr entry.

Related Technology

Passenger is a deployment configuration that is different from FastCGI. Dreamhost supports it, but I haven't gotten it to work yet.

Capistrano has something to do with automating common server tasks, like application deployment.

No comments:

Post a Comment