Posted by: tszao | September 6, 2007

Set up Rails on Site 5 Tutorial

This is a combination tutorial from these 2 sources.
http://forums.site5.com/showthread.php?t=4406
http://wiki.rubyonrails.org/rails/pages/HowToInstallOnSite5

It took both of them to get my site up and running in a Site5 hosting environment the way I wanted it to. I will also toss in some observations along the way and try to explain the process a little better as I go. Also, this is for a base install. I will add one controller and adjust the routing so that it is the first thing you see when you type in your site’s URL.

1) Gain shell (ssh) access to your site root. You may have to submit a ticket to Site5 and they will be able to hook you up. All of this stuff has to be done on the command line. For a GUI junkie like me this was a pretty steep curve to get used to. Luckily, I have done a little command line stuff in my past. The preference is a GUI tool if possible. You have to be in the area that you will see your “public_html” directory this is your site root. This is important because it will get changed a little later as the site gets set up to be run from the URL that you are going to use. For this example I will use the site that I needed to set up, musthatedebt.com. Just change out my site names for yours in the tutorial.

NOTE: If, in the command prompt, you need to get to the root of your site type this “cd ~” (without the quotes) and you will be transported back to the root of your site.

2) At the command line type:

> rails musthatedebt

This will install the base Rails application. As tempting as it is to go and look at the pretty default screen, avoid it for now. At least try to avoid it. We will have something to look at soon.

3) You will now need to create a symbolic link (symlink for short) to remap you application. Type this at the root of your site:

>ln –s musthatedebt/public/ public_html/mhd

I used a short name for the site here to make the link easier to read but also symlinks don’t really like mapping to a name that is similar. This was the same for both of the tutorials mentioned above and I found it to be true also. The main reason for this is to move the application files away from public consumption. You will only want to give access to your “public” directory in your rails app file.

4) We need to adjust the public_html/.htaccess file. I prefer to use the “nano” text editor but if you know how to use “vi” have at it.

> nano public_html/.htaccess

Inside the nano editor add the following lines of code

Options +FollowSymLinks +ExecCGI
RewriteEngine On

I personally added this at the bottom but as you will see in a little bit it will not matter.

NOTE: To save the file you will need to press the “ctrl”+”o” keys. Nano will ask you if you want to write the changes to the file and all you have to do is hit enter. To exit from nano you will need to press the “ctrl”+”x” keys. It will take you out of the program if you have written the changes and will ask you to save if you have not.

5) You will need to make the files executable so they will function properly on the server. Basically the command says to set all the files in the directory “musthatedebt” to be executable but not modifiable by the general public. There is more too it but that is not with in the scope of this tutorial. At the root of your site type the following:

> chmod –R 755 musthatedebt/*

6) We will now need to walk down our directory tree to the following folder:

>cd musthatedebt/public

In here is a file called “dispatch.cgi”. The first line of this file should look like this “#!/usr/bin/ruby” (without the quotes). The main reason for this is because if you went ahead and uploaded your main working directories from your development system you may not have the same Ruby paths setup as Site5.

Note: I am set up using Instant Rails on a Windows box and mine looks like “#!C:/InstantRails/ruby/bin/ruby”. The same is true for the “dispatch.fcgi and dispatch.rb”. To make the needed changes open up the file(s) with nano.

>nano dispatch.cgi

Adjust the line to make it look like “#!/usr/bin/ruby” (without the quotes), write out the file, and exit back to the command prompt. Do this for the dispatch.fcgi and the dispatch.rb while you are at it. At this stage you may be asking, “Why aren’t we using fastCGI?” This is because this is a base install with the configuration that Site5 gives you. I will talk more about fastCGI in the next tutorial.

7) Delete the default index.html file located in the “public” directory.

Here is how you do this from the root of the site:

>cd musthatedebt/public
>rm index.html

This is pretty easy to do and it is necessary. If the index.html file is still available, then Rails will show it. It is the first thing Rails looks for and will discount all routing if it is in place.

8 ) You will need to add a default controller to the site so that you have something to route to when we go to adjust the “routes.rb” file. Here is how you do this and yes we will start in the root of the site again.

>cd musthatedebt
>script/generate controller Site index

You will see a series of files generated and you will have a new controller to route to.

9) Now you will need to adjust the “routes.rb” file. From the root of the site you will need to type the following:

>cd musthatedebt/config
>nano routes.rb

Once inside the nano editor you will need to uncomment the following line.

# map.connect ”, :controller => “welcome”

and make it look like this:

map.connect ”, :controller => “site”

Write out this file and exit back to the command prompt.

9) Next you want to tell the server to run in production mode. To do this you will need to go to the “environment.rb” file. Here is what you need to do from the root of the site:

>cd musthatedebt/config
>nano environment.rb

Once inside the nano editing environment uncomment the following line:

# ENV['RAILS_ENV'] ||= ‘production’

to make it look like this:

ENV['RAILS_ENV'] ||= ‘production’

and add the following line just below it:

RAILS_ENV = ENV['RAILS_ENV']

Write these changes to the file and exit.

10) The last step is to make the site visible from the root so that when someone types in www.musthatdebt.com you see your application.

To accomplish this we will have to generate another symlink. Here is how this works from the root directory of you site.

First rename the current “public_html” directory like this:

>mv public_html public_html_back

then add your symlink to point to the public file in your application directory like this:

>ln –s ~/musthatedebt/public ~/public_html

After you do this you should be able to go to your website and see it smiling back at you with the default index for the site telling you where to go to change the text.

Final disclaimer, if you have been reading my blog for long you will know that I am still very green with it comes to Ruby and Rails. I think I have hosed my attempt at getting the musthatedebt.com site running about 3 times now. By following these steps, I was able to quickly get the site up and running again so that I can start the process all over.

Enjoy


Responses

  1. Thank you so much for this tutorial! I have been so frustrated trying to get my site up and running in Rails. I have tried to follow the same two tutorials that you reference at the top (and others) and I have sent emails to site5 hoping for some help, but it was your page that finally got me up and running! Thank you.

  2. Glad it was useful for you Anthony. Enjoy!!


Leave a response

Your response:

Categories