First you need to set up the databases your application will use. Do this in the Backstage admin area. You will need the names of the databases later to put into your database.yml file.
You also need to have ssh access to the server. You might need to submit a support ticket to have this enabled. To see if you have ssh access attempt to log in: go to an ssh terminal (eg putty on windows or the standard terminal on mac/linux) and type
ssh user@yourdomain.com
If you have ssh access you should then be prompted on whether you want to recognise the site's key (if it is the first time you have visited it) and then for your password. On logging in you should be presented by a command line prompt in your terminal. This is how we are going to interact with the server to set up the app.
You then need to upload your app to the server. I used an FTP client for this and uploaded it into a file called "apps" in my home directory on the server.
Navigate into your app folder on the server:
cd ~/apps/myapp
Set the correct permissions on the application files (not sure if these are the best permissions to set, but it works):
chmod -R 755 myapp
The files dispatch.cgi, dispatch.fcgi and dispatch.rb in the myapp/public directory are somehow involved in loading the cgi/fcgi/rb processes for serving the web app. We need to tell these where to find ruby, which is different on the server to where it (probably) is on your local computer. Change the first line of each of these files to
#!/usr/bin/ruby
If you now navigate to the myapp/public file and run
./dispatch.fcgi
you should get the html associated with your application root (identified through map.root in config/roots.rb) spat into your terminal window.
Go to the myapp/config/environment.rb file and uncomment the
ENV['RAILS_ENV'] ||= 'production'
line, to put the rails app into production mode.
We also need a .htaccess file in the myapp/public directory to tell requests that get redirected to this directory to be handled by the fcgi process. This .htaccess file used to be generated by the rails scaffolding but, from rails 2.0.1 onwards, isn't anymore. I used the following .htaccess file taken from an earlier app:
# 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.cgi [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 "Application error
Rails application failed to start properly"
Either upload this file using ftp or use a command line text editor (eg vi/nano/emacs) to create and save it.
We now need to provide a symlink so that users visiting yourdomain.com will be redirected to the public file in your app (and then dealt with via the fcgi handler) instead of just seeing whatever is in your ~/public_html folder. I did the following:
cd ~/public_html
ln -s ~/apps/myapp/public another_name_for_myapp
Note: it is important to use a different name as symlinks seem to get upset if you use names that are too similar.
We also need to have a .htaccess file in this folder to tell the web server to use the symlink. Upload/create the following file to the ~/public_html directory:
Options +FollowSymLinks +ExecCGI
RewriteEngine On
Now by visiting yourdomain.com/another_name_for_myapp you should be directed to the root of your application.
You will need to put your database settings into your database.yml file and then create and migrate your databases.
No comments:
Post a Comment