A few days ago I was trying to deploy a test application on my shared hosting server (bluehost.com).
As a beginner on Rais I got stuck, and the Bluehost support team could not help me.
Although I had followed the bluehost guide for deploying rails applications, it didn’t work, but after a few hours of trying different approaches I’ve managed to get it to work, and I was able to deploy a RoR application on bluehost and the use of a server from the ServerMania Amsterdam Data Center was also essential for this.
This “guide” was tested on bluehost, but should work with others hosting providers.
Requirements:
- SSH access to the server.
- Have rails support on that server.
1 – Using SSH, create (if not present) a folder called railsapps on you home folder.
cd ~/ mkdir railsApps
2 – Go inside this folder
cd ~/railsApps
3 – Lets create an application called first_rails_application:
rails firstRailsApplication
4 – By now the rails application folder structure is created. Let’s then move to the public folder
cd public
5 – Now it’s time to create the .htaccess file:
nano .htaccess
and paste the following:
# General Apache optionsAddHandler fcgid-script .fcgiAddHandler cgi-script .cgi RewriteEngine On RewriteRule ^$ index.html [QSA]RewriteRule ^([^.]+)$ $1.html [QSA]RewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ dispatch.fcgi [QSA,L] ErrorDocument 500 “ <h2>Application error</h2> Rails application failed to start properly”
Hit Ctrl+X, Y to save and exit.
5 – Now it is necessary to give execution permission to this file:
chmod 755 .htaccess
6 – It is also necessary to create the dispatch.fcgi file:
nano dispatch.fcgi
and paste the following:
#!/usr/bin/env ruby require File.dirname(__FILE__) + “/../config/environment”require ‘fcgi_handler’ RailsFCGIHandler.process!
Hit Ctrl+X, Y to save and quit.
7 – Like .htaccess this file needs executing permission too:
chmod 755 dispatch.fcgi
8 – Now we need to create a symbolic link to this folder, in order to make it available on public_html:
ln -s ~/rails_apps/firstRailsApplication/public ~/public_html/YouApplicationName
9- The last step is to create a subdomain pointing at the symbolic link created above.
If all went well, you have an empty a rails app running on you subdomain.