In setting up the launching pad for what I suppose will be my second endeavour in the “Web 2.0” application market following the initial beta launch of FiveRuns which went live last week, I quickly transformed the static “coming soon” page for remarkr into a simple Rails application to handle beta/information signups.
Local development with Rails is simple using either the default Webrick server or mongrel, but moving the application to my web-host of choice, Dreamhost proved to be a bit frustrating. It all worked in the end, but was made tedious by some wonky documentation. In the hopes of saving someone else the same trouble I ran into, here’s some additional notes on getting your Rails app running at Dreamhost.
I’m assuming you’ll be running the application from the web-root, meaning the main page of your app would be displayed if the user went to
www.yourdomainname.com, and not
Before you do anything, be sure to create a database instance to use for your domain. Make a note of the address, username and password as you’ll want that information for the
database.yml configuration file which should go under
You’re ready to upload your app via FTP. Dreamhost apparently requires most of the directories for your Rails app to have
766 permissions for folders and
664 for most files, the exceptions being your public directory and the log directory which can be set to
755. If you are getting weird errors and things aren’t running as expected, this is something to check.
config/environment.rb file, be sure to uncomment line 5 to set the
ENV['RAILS_ENV'] variable to ensure your app runs in Production mode.
ENV['RAILS_ENV'] = 'production'
While you’re at it, you may also want to store sessions in the database, and if so, uncomment line 28.
If you are planning sending e-mail from your Rails app, you’ll need to set some defaults for ActionMailer as Dreamhost requires you to use smtp and to authenticate to the mail server in order to send mail. I recommend reading the mailers examples on the Rails Wiki.
Lastly, in order for URLs to be redirected properly, you may (this may be deprecated with Rails 1.1.2 and newer) need to add one last line to the end of the
environment.rb configuration file. If so, it should look like this:
# Extra configuration to fix Dreamhost Routing problems # Make sure to also uncomment the ENV variable (see line 5) above to set ActionController::AbstractRequest.relative_url_root = "/appname"
Dreamhost Web Admin Configuration
Now you’re ready to make a small adjustment to the default domain setup. Essentially rather than leaving the Web Directory at “/”, we need to tell it to use the public directory for our app.
So, if your application was called addressbook, your Web Directory would be
domain.com/addressbook/public. Simple right? While you’re at it, make sure you have the Fast-CGI checkbox checked.
The last thing we need to adjust how the application is dispatched which means two more small adjustments.
Open up the
.htaccess file in
public and set the default redirect rule for dispatching Rails to use the fcgi script. Change line 28 to read:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
The last is changing the shebang line in
dispatch.fcgi which you can find in the
public directory of your application. For Dreamhost, it should be set to:
This will locate ruby and should generally work even in your development environment.