How to Setup Ruby on Rails on Webhost
In this tutorial, we are going to set up a Ruby on Rails application on our webhost at the subdomain http://firstruby.learnwebtutorials.com First make sure that your webhost has an Ruby on Rails environment for which to run our app — not all hosts do. Hostmonster and Bluehost both has it. And we will be using Hostmonster in this example.
You will also need to have SSH shell access to your webhost account. This may be something that you have to ask your webhost for.
1. After logging into SSH shell, we can confirm that Ruby is up and running on our host by typing …
and it should return the version of Ruby running. In our case, it is 1.8.7.
2. Then type …
This confirms that Ruby Gems package manager is also running. Ruby on Rails is a Ruby Gem.
3. Confirm that Rails is running by …
Our version that is showing is Rails 2.3.11
4. If the version of Rails is 2.x, create a new Rails app by typing …
rails -d mysql ~/rails_apps/firstruby
If Rails 3.x, then type …
rails new -d mysql ~/rails_apps/firstruby
Ruby on Rails requires a database. The -d mysql indicates to use a MySQL database.
The rails command creates a folder firstruby within the rails_apps folder that is on the user home directory. firstruby will also be the name of the Ruby on Rails application.
The folder “public” that is inside the newly created “firstruby” folder is your rails application public folder. This is where files of the application are placed for the public to access via the webserver.
Alternatively, on certain webhost you can create a Ruby application folder via the cPanel by clicking on “Ruby on Rails” service …
And then filling in the following …
And click the green “Create” button.
5. We have already created our subdomain http://firstruby.learnwebtutorials.com (see tutorial here) for which we intend to be the web address of our Ruby on Rails app. The document root for this subdomain was already set up to be ~/public_html/firstruby
Here is what our current subdomain looks like …
6. Instead of this page referencing the the location at ~/public_html/firstruby, we want it to reference the Rails public folder that we had just created (which is ~/rails_apps/firstruby/public). Since the Rails public folder is outside public_html, we have to create a symbolic link to it.
We want a symbolic link named at ~/public_html/firstruby to link to the real location at ~/rails_apps/firstruby/public
But we can not do this with a real directory ~/public_html/firstruby in place.
So we delete the ~/public_html/firstruby directory. And then create the symbolic link with this command in the SSH shell…
ln -s ~/rails_apps/firstruby/public ~/public_html/firstruby
The ~/public_html/firstruby is our symbolic link. It is not really there. It is like an “alias” to the real location at ~/rails_apps/firstruby/public
7. So when you browse in your browser to http://firstruby.learnwebtutorials.com you are really looking at the Rails public folder. And you should see the Ruby on Rails Welcome page …
That it. The firstruby Ruby on Rails app is up. From here, you would configure and code your Rails app.
To Delete a Rails App
To remove a Rails app, “unlink” the symbolic link. And delete the folder from ~/rails_apps/firstruby
And then you may also want to remove the subdomain.