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.
Assumptions
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 app.yourdomainname.com
.
Baby Steps
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 production
.
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.
Configuration
In your 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.
Dispatch!
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:
#!/usr/bin/env ruby
This will locate ruby and should generally work even in your development environment.
That’s it. Assuming all went well you should have a Ruby on Rails application up and running on Dreamhost.
So say you…
I really know what you’re talking about. Deploying my Rails application to Dreamhost really wasn’t easy but I’m now using Capistrano which eases the pain to a one-time-only event.
Kitto June 13, 2006
I started to look at Capistrano but decided to start off without it. Not sure how much it would have helped me this time round, but when it’s time to go live for real with something more than a simple beta sign-up app, it’ll be worth the time/effort.
Scott June 14, 2006