I have been using Site5 for over a year now and their system has been running Rails 1.2 since I started. Well, they now have some Rails 2.2.2 servers and it took me a week to get everything figured out so that I could get a client site setup. Here are the steps that I went through.
Setting up a web site on a Site 5 Rails 2.2.2 server.
The first thing you will need to do is setup your production database. This will be important later in the process of setting up your site.
Login to your Site5 account with your favorite SSH tool.
At any point you can use the command
$ cd ~
to get back to your root directory.
The first thing you will need to do is to run the rails script with the mysql database flag.
$ rails -d mysql nameyoursite
You will see a series of create statements and will also have a new directory.
Change directories into your new nameyoursite directory
$ cd ~/nameyoursite
Next add a controller that will be used later.
$ ruby script/generate controller site index
If all goes well, you will see the script run and add some more files to your system.
You will now need to move to the config directory to take care of a few things there.
$ cd ~/nameyoursite/config
In this directory, the first file to edit is the database.yaml. I use nano, others use VI. I say use whatever makes you comfortable.
$ nano database.yml
Ok, this is where it gets a little harry. In previous versions of Rails on Site5, the only thing you had to change was the values of the production database. However, all of the extra code causes errors with starting up the rails environment. Here is the only code you will need.
production:
adapter: mysql
encoding: utf8
database: nameyoursite_databasename
pool: 5
username: username
password: password
socket: /tmp/mysql.sock
NOTE: This is important. I am not sure this is the case for all of the servers, however I found it to be true on the one I was working on. You will need to use the username and password that Site5 sent you for the SiteAdmin. The “additional users” for the database do not work as of the writing of this how-to.
After you have made the changes, save the file and exit.
Next you will need to edit the environment.rb file.
$ nano environment.rb
Remove the # from the line that looks like this
# ENV['RAILS_ENV'] ||= ‘production’
and make it look like this
ENV['RAILS_ENV'] ||= ‘production’
Again save the changes and exit.
Now change directories back to the root of your site.
$ cd ~
Next, create a symbolic link, or symlink if you prefer, that will map your public directory to the public_html directory. It is important to note when creating the symlink to use a shorter name on the mapped name. I am not sure why and if someone could explain it to me I would greatly appreciate it.
$ ln -s nameyoursite/pubilc/ public_html/nys
Now change the file permissions to make them executable with the system.
$ chmod -R 755 nameyoursite/*
From here you will want to make a back up of your public_html directory and to do that you can run the following command from the ~ directory.
$ mv public_html public_html_back
When that is completed you will now create a new symlink form your application public directory to the a linked public_html directory in the ~ of your site.
$ ln -s ~/nameyoursite/pubilc ~/public_html
Now you will need to add a .htaccess file to the application public directory.
This is what the file will look like.
—- Start .htaccess file – copy below this line —
# General Apache options
AddHandler fastcgi-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
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”
— End .htaccess file – copy above this line —
Change directories to your application public directory.
$ cd ~/nameyoursite/public
Create a .htaccess file and populate it with the information above.
$ nano .htaccess
Save the file and exit.
Next we want to set the route to our generated controller. So go back to the config directory.
$ cd ~/nameyoursite/config
Open up the routes.rb file with your favorite editor.
$ nano routes.rb
Uncomment the following line
# map.root :controller => “welcome”
and make it look like this
map.root :controller => “site”
and finally remove the index.html file from the application public directory.
$ mv index.html index_old.html
Now all that is left is to go and visit the site to see if it all works.