A quick and dirty tutorial to get a new Ruby on Rails application running on your [DreamHost](http://www.dreamhost.com/r.cgi?488244/hosting.html|EDDIESAVES “Save $50 off the yearly cost of hosting with Promo Code “EDDIESAVES”") server. In am going to concentrate on the easiest method, which is to use the Phusion Passenger module, a.k.a. ‘mod_rails’.
Some wise warnings from the DreamHost Passenger Wiki page;
Alright, so without further adue I will jump into the process of getting a Ruby on Rails application to run on DreamHost servers.
Special thanks to members of the DreamHost support wiki and RubyDreams for inspiration and guidance.
Sign up with DreamHost I imagine if your reading this article then you’ve done this step - Congratualtions! But just in case here’s $50 towards your first year.
Activate mod_rails This is very easy, and very important. When you are setting up a new domain, be sure to check the ‘mod_rails’ checkbox. DreamHost Panel > Manage Domains > (Add or Edit) [caption id=“attachment_546” align=“aligncenter” width=“300” caption=“Setting up the domain to use Passenger”][/caption] DreamHost will yell at you and say something about a public directory. Just append the word ‘public’ to the end of the path, e.g. “/home/username/mynewdomain.com/public”. This directory will be populated in the following steps.
Create DB - will be ready by the completion of next step Use the DreamHost web panel to create a new DB. Goodies > MySQL Databases > Create New [caption id=“attachment_547” align=“aligncenter” width=“300” caption=“Setting up a new DB on DreamHost”][/caption]
Create Rails app For this you’ll need to open up your favorite console and ssh to your DreamHost account. Navigate to your webroot directory and type the following;
$ rails -d mysql mynewdomain.com
(I have a standard of putting all domains in a folder called webroot, so my full path is /home/username/webroot/mynewdomain.com ) You can browse around now and notice several created directories and files including the ‘public’ folder required above.
Edit DB Connection Strings Of course we need to tell our Ruby app about the DB, and how to connect. Open the file /yourapp/config/database.yml Edit the parameters;
development: adapter: mysql encoding: utf8 database: my_ruby_app_db pool: 5 username: unsername password:dbpassowrd host: mysql.host
Prepare the DB for use By now the new DB should be up and running thanks to one of many Happy DreamHost Robots. cd into the directory created in the last step;
$ cd mynewdomain.com $ rake db:migrate
This will ensure your connections strings are correct and the DB is ready.
Restart Rails This is the area that was unknown to me as a total Rails newbie. You can always restart your application and clear any cached configuration information by throwing a special file into the tmp directory.
$ touch tmp/restart.txt
Hooray! That’s it. In about 15 minutes you have created a new Ruby on Rails application. At this point it is a pretty useless application. But don’t let that dishearten you, there are lots of great tutorials that will show you how to make something useful! Like this one for example. You can skip the DB and basic setup and jump right into the coding - http://guides.rubyonrails.org/getting_started.html