How do i View, Stop and Start my Ruby app via SSH
February 11th, 2010
February 11th, 2010
February 10th, 2010
SSH Access
You will have to have to request jailed SSH access on your hosting account by submiting a support ticket. You can then use SSH to execute commands (rake, script/generate etc) like you would locally.
To log in to SSH run:
ssh -p 2222 username@example.com
Creating Application
Even though you have created your app locally, you want to create a new app in SSH (and let it create the folder hierarchy) and then replace all the controllers/views/models/db/config etc with your app.
To create the new app in SSH:
First navigate to a location where you want to create the new app folder – it doesn’t matter where, although cpanel likes to put them in ~/etc/rails_apps/.
Run:
rails -d mysql --with-dispatchers mynewapp
You now need to upload your locally created app to the server using FTP or otherwise. Don’t overwrite the files yet! Create another folder out of the way and upload it there for now. You have to be careful when overwriting the ssh created app that you don’t accidentally wipe some necessary files.
You can completely overwrite all files and folders EXCEPT the public folder. When dealing with the public folder, I suggest you overwrite the individual images, stylesheets and javascripts folders without touching the files already in /public/.
Specifically: public/dispatch.rb , public/dispatch.cgi and public/dispatch.fcgi must all be present otherwise your app will not function.
Once you’ve got your locally created app in place go on..
.htaccess
To get the app running properly it is necessary to edit .htaccess.
Navigate to ~/etc/rails_apps/mynewapp/public:
cd /etc/rails_apps/mynewapp/public
To open .htaccess
pico .htaccess
Regardless of whether there’s already text in the file or its blank, the only necessary code is as follows:
AddHandler fcgid-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/notrails.*
RewriteRule .* - [L]
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
Save the .htaccess file
Database Setup
In cpanel go to MySQL databases and create a new database:
eg. New database: records
Note that cpanel will automatically add username_ to the front of it, thus database name is:
username_records
You also need to create a user for this database:
eg. Username: gkumar
pw: *****
Note that cpanel will also append username_ to the front of each user too, thus database user will be:
username_gkumar
Finally in cpanel Add user to database: username_gkumar to username_records.
You can now use this database, username and password in database.yml
Database.yml
in SSH or filemanager:
cd /etc/rails_apps/mynewapp/config/ pico database.yml
Setup database.yml for above example:
development: pool: 5 timeout: 5000 adapter: mysql database: username_records username: username_gkumar password: ******* socket: /var/lib/mysql/mysql.sock # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: mysql username: username_gkumar password: ******* socket: /var/lib/mysql/mysql.sock pool: 5 timeout: 5000 reconnect: true socket: /var/lib/mysql/mysql.sock
Note: Leave test alone (if you setup test like the prod and dev you might accidentally wipe the database if you run a test). Take note of the adapter and socket, they need to be setup for mysql not sqlite.
Symlink
Currently we have the app loaded at /etc/rails_apps/mynewapp. However, pages that are visible on the web need to be in the /public_html/ directory. Because of the way rails separates public from models/views etc, we use a sym link to make the files from /mynewapp/public appear also in /public_html/. It will essentially seem like the one folder (public) has 2 different paths to it.
Do you want the app to be displayed at www.example.com/ or www.example.com/blog/? Do you have addon-domains or is this your only domain?
Case: Display at example.com/ and yes I have addon domains
If we want to display at example.com/ we need to create a symlink to /public_html/. The issue is that you must delete public_html and then recreate it with the symlink. (can’t symlink to an existing folder) As you probably know, addon domains are stored in /public_html/addondomain.com/. To ensure that you don’t loose you addon domain data it is necessary to:
1. Copy the addondomain.com folder/s elsewhere
2. Delete public_html
3. Create the symlink (which will recreate /public_html)
4. Copy the addondomain.com folder/s back to their original location
So assuming you’ve backed up you addon domains and deleted public_html:
In SSH (at /home/username/) execute:
ln -s ~/etc/rails_apps/mynewapp/public ~/public_html
You will now find that in public_html you have the files and folders (images/stylesheets etc..) that are located in /mynewapp/public. Don’t forget to copy back you addon domains.
This is the hardest scenario, if you have no addon domains – obviously the same procedure applies without needing to backup anything.
If you want the rails app to display on an addon domain:
ln -s ~/etc/rails_apps/mynewapp/public ~/public_html/addondomain.com
If you want the rails app to display at mydomain.com/blog: (ensure no folder named blog exists)
ln -s ~/etc/rails_apps/mynewapp/public ~/public_html/blog
Also add to mynewapp/config/environment.rb:
ENV['RAILS_RELATIVE_URL_ROOT']="/blog"
Environment.rb
At the top of the file you can add:
ENV['RAILS_ENV'] ||= 'production'
In the Rails::Initializer.run do |config| block:
config.load_paths += %W( #{RAILS_ROOT}/vendor/plugins )
Gems
You can also have problems if you are using gems in your app that SpeedHost hasn’t got installed. You can view which gems are installed in cpanel RubyGems and also install gems through cpanel. If there is a gem missing from our server, you can send us an email and we will have it installed on the server.
February 7th, 2010
Most Ruby (RoR) Gems are already installed on our servers and can we used by you, however there might be some specialized gems which you may want to install. This can be simply done by the command below.
run gem install <gem name>
If you have any problem, you can always raise a support ticket and we will have our Ruby admin install the gem for you.
February 6th, 2010
1. Login to your SSH using your own account.
2. Once logged in make sure you are in your /home/username folder using the “pwd” command.
It should show the output like this:
cpaneluser@server [~]# pwd /home/cpaneluser
3. Then run the following commands to generate a demo rail app and its controller.
cpaneluser@server [~]# rails /home/cpaneluser/demoapp cpaneluser@server [~]# cd demoapp cpaneluser@server [~]# ruby script/generate controller test
4. Now create a symlink in public_html so that the app is viewable via the web.
cpaneluser@server [~]# cd ../public_html cpaneluser@server [~]# ln –s ../demoapp/public rails
5. Before you test the Rails page, there is one more modification you need to make.
cpaneluser@server [~]# cd ../demoapp/public cpaneluser@server [~]# pico .htaccess
Locate the line where it has the code like below:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
Change that code to:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
You can then visit http://example.com/rails/ and you should see a “Welcome Aboard” page which confirms successful working of your rail app. You can deploy any other standard Rail applications as well. Most of them should work well with the preinstalled Gems we have.
February 5th, 2010
The following Gems have been preinstalled with the Ruby installations. Custom gems are avaliable on a per request basis. If you need an additional gem installed, please create a support ticket.
Actionmailer
Service layer for easy email delivery and testing.
Actionpack
Web-flow and rendering framework putting the VC in MVC.
Actionwebservice
Web service support for Action Pack.
Activerecord
Implements the ActiveRecord pattern for ORM.
Activesupport
Support and utility classes used by the Rails framework.
BlueCloth
BlueCloth is a Ruby implementation of Markdown, a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).
Builder
Builders for MarkUp.
Daemons
A toolkit to create and control daemons in different ways
Feedtools
Parsing, generation, and caching system for xml news feeds.
Gem_plugin
A plugin system based only on rubygems that uses dependencies only
Gnuplot
Utility library to aid in interacting with gnuplot
Htmltools
This is a Ruby library for building trees representing HTML structure.
Mongrel
A small fast HTTP library and server that runs Rails, Camping, and Nitro apps.
MySQL
MySQL/Ruby provides the same functions for Ruby programs that the MySQL C API provides for C programs.
Payment
Payment is used to process credit cards and electronic cash through merchant accounts.
Rails
Web-application framework with template engine, control-flow layer and ORM.
Rake
Ruby based make-like utility.
Sources
This package provides download sources for remote gem installation
Tidy
Ruby interface to HTML Tidy Library Project
Uuidtools
Generation of UUIDs.
Xml-simple
A very simple API for XML processing.
We are offering jailed SSH access on all our servers. You can get SSH enabled for your account if you want to deploy and test Rails applications rapidly. The procedure to get SSH access is simple. You can order SSH while you are taking hosting from us or later by raising a support ticket from SpeedHost admin area.
