Setting up Ruby on Rails at Bluehost

I recently hosted my Ruby on Rails (ROR) application at Bluehost and I am laying out a step by step approach. I have tried to keep it as simple as I can.

The following steps are for setting up ROR application in a shared hosting environment at Bluehost. Bluehost does not let you use mongrel in a shared hosting as this requires running the server at a different port (12010 etc..). In order to use mongrel you need to have a dedicated IP.  In a shared hosting environment you will need to enable FastCGI in your web server ( Apache). Also the following example uses an Add on Domain .

1) SSH Access: Call up or email bluehost to give you SSH access ( bluehost instructions).

2) Addon Domain: Go to Domain Manager in CPanel and Add on a domain. Lets say you have a site www.example.com and you want to host another domain ( www.myrubyapp.com) in the same hosting plan. You can go to the CPanel and select CPanel->Domains->Addon Domains. It will take you to the Domain Manager and let you add another domain. You will first need to set the domain name servers for the domain you want to add to “ns1.bluehost.com” and “ns2.bluehost.com“. It will let you map your new domain to a subdirectory in “/public_html”. For e.g. http://www.myrubyapp.com could map to “/public_html/myrubyapp” directory.

3)Create Rails App: You can either do this from SSH or from CPanel. Select Cpanel->Software Services->Ruby on Rails. Give the application name e.g. “myrubyapp“, set the application path “/railapps/myrubyapp“, select “production” environment and click on create. This will create your application.

4) Create Symbolic Link: You will need SSH access to accomplish this. Once you have SSH access then select Cpanel->Security->SSH Access and log in using your username and password (bluehost instructions).  Next we need to map the ~/public_html/myrubyapp directory to /home/<username>/railapps/myrubyapp directory. Before that we need to delete the ~/public-html/myrubbyapp directory.  Run the following command:

  • cd ~/public_html
  • rm -rf  myrubyapp
  • ln -s /home/<username>/railapps/myrubyapp/public  myrubyapp

5) Verify Ruby on Rails Welcome Page: If all the steps were executed correctly you should see the Ruby on Rails welcome page by going to http://www.myrubyapp.com. This is going to display the index.html page located in /home/<username>/railapps/myrubyapp/public directory.

6) FASTCGI Setup (.htaccess): In order to invoke your ruby application via Apache you need to enable/configure FASTCGI for apache. This is achieved by creating a .htaccess file in /home/<username>/railapps/myrubyapp/public and adding the following entries:

# General Apache options
AddHandler fcgid-script .fcgi
AddHandler cgi-script .cgi
#Options +FollowSymLinks +ExecCGI

# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
#
# Example:
#   RewriteCond %{REQUEST_URI} ^/notrails.*
#   RewriteRule .* - [L]

# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On

# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
#   Alias /myrailsapp /path/to/myrailsapp/public
#   RewriteBase /myrailsapp

RewriteBase /
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
# Example:
#   ErrorDocument 500 /500.html

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

7) Setup the database: Using CPanel MySQL wizzard create a database, username and password.  Lets say you enter myrubyapp (database name)  admin ( database user) and admin123 ( database  password). Bluehost will prefix your database and database username with your domain username “<username>_”. The database will be <username>_myrubyapp and db user will be <username>_admin.  Give the database user full privileges. Update the database.yml file in your ruby applicationwith correct information. If you are using production environment then uncomment the following # ENV['RAILS_ENV'] ||= ‘production’ in your environment.rb file in your app config directory.

8) Map the Root: The domain is currently pointing to the Ruby on Rails welcome page. You will need to point it to your app. Delete or rename the index.html page.  Lets say the index page of your application should point to a controller resource  myrubyappresource and the action is “show“. The following entry needs to be entered in your routes.rb file.

  • map.root :controller=>’myrubyappresource’, :action=>’show’

9) Fire up the application: If all was configured properly you should be able to see you application now at http://www.myrubyapp.com.

10) Deploying updates: When you viewed your app url in a browser, the web server ( apache) started up a process for fastcgi. You can view the process via CPanel->Advanced->Process Manager. Everytime you update your application you will need to kill this process to make the updates visible to the users.

References: http://helpdesk.bluehost.com/kb/index.php?x=&mod_id=2&id=232

I had to struggle through multiple issues to get my app to work with Bluehost. The intent of this article is to make it easy for folks deploying their ruby app with Bluehost for the first time. Hope this helped. If you have any questions please feel free to ping me.  So long..

Share/Save/Bookmark

Tags: , , , , , , , , , , ,

24 Responses to “Setting up Ruby on Rails at Bluehost”

  1. Carlos Kelly Says:

    It is also easy to backup and transfer all your websites from one server to another server if you have cPanel installed”*”

  2. Lakeesha Botto Says:

    Hi. I read a few of your other posts and i wanted to say thank you for the informative posts.

  3. Cassaundra Hergenroeder Says:

    Hey – I’m speaking to a ton of site owners to discover out out if they’ve heard something in regards to the unbelievable blog website web page engine alteration that is contained in the works? With WP releasing 3 somewhat shortly, the phrase on the road is that BE is going to make a tremendous quantity of adjustments that search like WP alterations. Shoot me an email occur to occur to ever hearken to everything.

  4. radek Says:

    hi,

    I am trying to install redmine.org on Bluehost. I was following redmine installation guide and I can access the redmine application for withing bluehost itself but not from outside. I guesss it is about setting up .htaccess and/or fcgi. But I do not know how to solve that. I tried to contact BH support :-(

    Any suggestions?

    Thank you

    Radek

  5. Pattaya Says:

    Sehr interessant. Kommt hier noch ein weiterer Beitrag? Möchte sehr gern mehr darüber erfahren. Kannst du mir per Mail antworten?

  6. kalkaop Says:

    I together with my pals were checking out the excellent tips and tricks located on your site and so immediately I had an awful suspicion I had not thanked the web blog owner for those strategies. Most of the ladies were for that reason joyful to read them and have in effect in fact been loving them. I appreciate you for being so accommodating and for having these kinds of awesome subject matter most people are really needing to be informed on. My personal sincere apologies for not expressing gratitude to sooner.

  7. Whitney Slaby Says:

    Sensible informative post. I will visit your site often to stay updated

  8. hack facebook password mac Says:

    All I can express is, I’m not sure what to express! Except certainly, for the excellent tips that happen to be shared with this blog. I’ll think of a zillion fun ways to read the content on this site. There’s no doubt that I will eventually take action employing your tips on that matter I could not have been able to address alone. You’re so considerate to allow me to be one of those to profit from your valuable information. Please know how a great deal I appreciate it.

  9. Annelle Bialczyk Says:

    Just just just what is a blogging site that allows you to definitely certainly certainly certainly certainly certainly sync with facebook for comments?

  10. Earlean Perkinson Says:

    I like studying and I conceive this website got some truly useful stuff on it!

  11. gogreen Says:

    Really informative and excellent bodily structure of subject material , now that’s user pleasant (:.

  12. Android Apps Says:

    I got what you plan, thanks for putting up. Woh I am pleased to comprehend this website through google. Thanks For Share Setting up Ruby on Rails at Bluehost | eSustain.

  13. Sharlene Burkes Says:

    I discovered your blog website on google and examine a number of of your early posts. Continue to maintain up the very good operate. I simply additional up your RSS feed to my MSN News Reader. Looking for ahead to reading extra from you in a while!…

  14. Dusti Beyene Says:

    This is very interesting, You’re a very skilled blogger.I’ve joined your feed and look forward to seeking more of your excellent post.Also, I’ve shared your web site in my social networks!

  15. cheapest vps Says:

    This web page is known as a stroll-via for the entire information you wanted about this and didn’t know who to ask. Glimpse here, and you’ll undoubtedly discover it.

  16. Ashton Gohring Says:

    Thank you for another excellent post.Where else could anybody get that kind of information in such an ideal way of writing? I have a presentation next week, and I’m on the look for such info

  17. pozycjonowanie Says:

    Thanks for including Marketing Pilgrim on the list! We’re one of the youngest sites on the list – gry - less than 2 years old – but glad to be in such great company.

  18. Peter Says:

    Hi, I did the same thing as you did, but now I want to change my ruby app to become the mail domain.

    Do you know how I need to setup my ruby files inside the public_html folder in order to work?

    I have current a main domain (e.g. maindomain.com), and my ruby app’s domain is ruby_subdomain.com

    and ruby_subdomain/public is linked to public_html/ruby_subdomain.

    If now I swap the two domain so the ruby_subdomain becomes the main domain, do I need to move all the ruby files into the public_html folder?

  19. Blair Coup Says:

    Hey There. I found your blog implementing msn. This is certainly a very well created piece of writing. I’ll make sure to bookmark it and return to examine more of your useful info. Thanks for that publish. I will definitely comeback.

  20. clearance sale Says:

    *There are definitely a lot of details like that to take into consideration. That is a great point to bring up. I offer the thoughts above as general inspiration but clearly you’ll find questions like the 1 you bring up where the most crucial thing is going to be working in honest good faith. I don?t know if finest practices have emerged about items like that, but I am certain that your job is clearly identified as a fair game. Both boys and girls feel the impact of just a moment’s pleasure, for the rest of their lives.

  21. Kraig Benford Says:

    Hi! I’ve just stopped by to say thanks for this interesting info. Take care!

  22. Christin Noh Says:

    For a Newbie, We are continuously doing a search online for articles that is of assist to me. Many thanks

  23. Loyce Durol Says:

    If former Chairman JC has any supporters that know the true story behind his removal, it would be great to hear your take on things? Did JC deserve removal? Does Selvage deserve to be sitting there when JC was removed for trumped-up charges?

  24. Escorts London Service Says:

    So much wonderful information on here.

Leave a Reply