Vixiom Axioms

February 4, 2008

LiteSpeed adds a Rails staging environment

Filed under: LiteSpeed, Mongrel, Ruby on Rails Alastair @ 11:54 pm

Via Dark as Light, the easy way to deploy Rails adds a staging environment.

Here are the LiteSpeed update instructions:

1. Click ‘update’ in the LiteSpeed administration console
2. There is no step 2
3. see #2

Why more people don’t use LiteSpeed is beyond me. Hosting a Rails app takes only a couple more steps with no mongrel_clusters or load balancing shenanigans.

Digg! submit LiteSpeed adds a Rails staging environment to stumbleupon.com submit LiteSpeed adds a Rails staging environment to del.icio.us submit LiteSpeed adds a Rails staging environment to reddit.com Like this post? subscribe to the feed.

May 26, 2007

Rails on a Media Temple (dv) server

Filed under: Media Temple, Mongrel, Ruby on Rails Alastair @ 3:28 pm

Tom at the wishlisting.com blog has a comprehensive tutorial on setting up Ruby on Rails (with a load balancer and Rmagick) on a Media Temple (dv) server. He deserves praise for installing ImageMagick without a package manager, which can turn into a marathon event of yak-shaving.

Digg! submit Rails on a Media Temple (dv) server to stumbleupon.com submit Rails on a Media Temple (dv) server to del.icio.us submit Rails on a Media Temple (dv) server to reddit.com Like this post? subscribe to the feed.

February 18, 2007

MT GS RoR A-Z: The complete guide to Rails on Media Temple’s Grid Server

This tutorial will walk you through setting up everything you need to deploy Rails apps on Media Temple’s Grid Server. The information on each part of the setup is available elsewhere but I thought it would be helpful to have it all in one place. The tutorial will cover setting up a rails container, creating ssh keys on the server, installing rails, creating a subversion repository, and deploying your app with Capistrano.

Prerequisites: You have a (gs) hosting account setup, a SSH client (OS X Terminal.app or PuTTy if you use Windows), and no fear of Unix commands.

Throughout the tutorial I’ll be calling the rails app ‘myapp’ replace that with the name of your application and ‘mydomain.com’ replace that with your domain.

1. SETUP THE RAILS CONTAINER

Log into your Media Temple account center and click on the ‘GridContainers’ control

In the Container List click ‘manage’ on the Ruby on Rails container

Enable the container by clicking ‘enable container’

Select ‘(gs) Container Base’ if you app will require the base amount of RAM, from experience unless you’re doing processor intensive things like resizing very large images with RMagick the base container will be fine.

Confirm the selection on the next page and then wait for your container to be enabled (takes about 5 min). Once you have the container enabled go back the main control panel, click ‘Server Administrator’ and make sure you have SSH enabled.

Since this is a Rails app you’ll most likely need a database, go back to the main control panel and click ‘Manage Databases’

Click ‘Add A Database’

Then in the ‘Specify Your Database Name’ field enter ‘myapp_production’ it’s actual name will then be db#{sitenumber}_myapp_production (sitenumber being your MT site number). Choose MySQL or PostgreSQL from ‘Select Database Type’ and click next.

The container is set up, next up SSH Keys.

2. SSH KEYS

SSH keys will allow you to log into your server without a password; "wait, no password, isn’t that insecure?" actually it’s more secure as long as you and only you have access to your local machine. Although SSH is very secure it’s still possible (though unlikely) for your password to be intercepted when you login. Setting up SSH keys, as the name implies, creates a key on the server that maps to your local machine (a known host), you then no longer have to enter your password when you login in which is safer and requires less memorizing and typing (my two least favorite things!).

Fire up the OS X Terminal (or PuTTy), once it launches you’ll be in your home directory. Type

$ ssh-keygen -t dsa

that will generate the keys on your local machine, change into the .ssh directory

$ cd .ssh

and copy the keys to your server (replacing ‘mydomain’ with your domain)

$ scp id_dsa.pub serveradmin%mydomain@mydomain:./id_dsa.pub

log into your server the old fashioned way

$ ssh serveradmin%mydomain@mydomain

then setup the keys and make sure no other users can read them (each command on a seperate line)

$ mkdir .ssh
$ cd .ssh
$ touch authorized_keys2
$ chmod 600 authorized_keys2
$ cat ../id_dsa.pub >> authorized_keys2
$ rm ../id_dsa.pub

Now when you login you won’t be asked for your password.

3. INSTALL RAILS

Log in (or remain logged in to) the server using you brand new keys.

Then setup another option to save typing your password over and over.

$ mtr generate_config

entering your username (serveradmin%mydomain@mydomain) and password. Then set up ruby gems (each command on a seperate line).

$ mtr setup_rubygems
$ source ~/.bash_profile
$ gem update --system --source=http://gems.mediatemple.net/

then install rails NOTE: running Rails 2.0 as a RubyGem is not yet supported see this article

$ gem install rails -y

and the appropriate database driver, for MySQL

$ gem install mysql --source=http://gems.mediatemple.net/

or for PostgreSQL

$ gem install postgres --source=http://gems.mediatemple.net/

Next install Mongrel

gem install mongrel --source=http://gems.mediatemple.net -v 1.1.1

If you wanted to you could now create a Rails app on the server, but first we’ll create a subversion repository…

4. SETUP A SUBVERSION REPOSITORY

Subversion is a great tool for tracking changes to an application when working with a team of developers or even or your own. You can roll back code to a previous revision and avoid overwriting another person’s work. On your Media Temple server change into your home directory then into the ‘data’ directory.

$ cd $home
$ cd data

and create a ’svn’ directory.

$ mkdir svn

Subversion is already installed on Media Temple so creating a repository is a one line affair

$ svnadmin create --fs-type fsfs svn/repository

That will create the ‘repository’ inside of the svn directory, next we set up the standard directories for Subversion. You need to type the complete path to your repository when adding directories. First find out your site number

$ pwd

This will spit out something like

/home/123/users/.home/data

‘123′ is your site number. In the command below replace mysitenum with that number (Note: using the backslash character means you can type multiple lines before issuing the command).

$ svn mkdir --message="Setting up the directories..." \
> file:///home/mysitenum/data/svn/repository/trunk \
> file:///home/mysitenum/data/svn/repository/tags \
> file:///home/mysitenum/data/svn/repository/branches

Running that command also commited your first revision to the repository (that was easy). The –message option lets others know what changes happened during a revision.

You can now load a rails app into your repository. On your local machine change into the rails app for the site you’re working with.

$ cd path/to/my/app

You’ll know if you’re in the right place if you type ‘ls’ and get a list of rails folders

$ ls
README          components      doc             public          tmp
Rakefile        config          lib             script          vendor
app             db              log             test

Subversion stores revisions in the ‘trunk’ check that out into your rails app (making sure to change mydomain.com and mysitenum to your variables). Note: the ‘.’ after trunk is required (it means do this here)

$ svn checkout svn+ssh://serveradmin%mydomain.com@mydomain.com/home/mysitenum/data/svn/repository/trunk .

Before we commit any files to the repository we should set some files to be ignored, like logs. First add all the files

$ svn add *

Then set the files you want to ignore

$ svn propset svn:ignore "*.log" log
$ svn revert log/*

Now you can commit your site to the repository

$ svn commit --message="Ini Rails App."

And update your code just to be sure you’re on the latest revision

$ svn update

You should get a message ‘At revision 2.’. Your app is now under version control! And the best reason to have it under version control is… Capistrano.

5. DEPLOYMENT WITH CAPISTRANO

Capistrano makes deploying your app as easy as typing one line, but first you need to set it up. Again on your local machine install Capistrano [UPDATE] Some people have had problems with Capistrano 2.0, I’ve changed the command to install 1.4 [/UPDATE]

$ sudo gem install capistrano -v 1.4.0

Then install Media Temple’s Capistrano

$ gem install mt-capistrano --source=http://gems.mediatemple.net/

And apply Capistrano to your app (make sure you’re in your app’s directory, note the ‘.’ means apply to ‘this’ location)

$ cap --apply-to . myapp

Next download the Media Temple deploy recipe from http://gems.mediatemple.net/deploy.rb (overwriting the one Capistrano made in myapp/config) then open deploy.rb and add your app’s info (all the lines that begin with ’set’):

require mt-capistrano

set :site,         "mysitenum"
set :application,  "myapp"
set :webpath,      "myapp.mydomain.com"
set :domain,       "mydomain.com"
set :user,         "serveradmin%mydomain.com"
set :password,     "xxxxxxxx"

# repository on (gs)
set :repository, "svn+ssh://#{user}@#{domain}/home/#{site}/data/svn/repository/trunk"

# repository elsewhere
#set :repository, “svn+ssh://user@other.com/usr/local/svn/repo/app1/trunk”
#set :repository, "https://other.com/usr/local/svn/repo/app1/trunk”
#set :svn_password, “xxxxxxx”

# these shouldn’t be changed
role :web, "#{domain}"
role :app, "#{domain}"
role :db,  "#{domain}", :primary => true
set :deploy_to,    "/home/#{site}/containers/rails/#{application}"

#set :migrate_env, "VERSION=0"

#task :after_update_code, :roles => :app do
#  put(File.read(’deploy/database.yml.mt’), "#{release_path}/config/database.yml", :mode => 0444)
#end

task :after_symlink, :roles => :app do
  run "#{mtr} -u #{user} -p #{password} generate_htaccess #{application}"
end

save the file and then modify your config/database.yml file to use the Media Temple database for your production environment.

production:
  adapter: mysql
  database: db123_myapp_production
  username: db123
  password: xxxxxxxx
  host: internal-db.s123.gridserver.com

then run a subversion status

$ svn status

you should see a couple of new files in there with ‘?’ before them, that means subversion doesn’t know about them. To add them type

$ svn add config/deploy.rb
$ svn add lib/tasks/capistrano.rake

Then commit them to the repository and update your local copy (Note: -m is shorthand for –message).

$ svn commit -m="config deploy.rb"
$ svn update

Now we can deploy the app so it will be live on your Grid Server domain. Run each of these commands on one line:

$ cap mt_add
$ cap setup
$ cap update_code
$ cap symlink
$ cap migrate
$ cap mt_create_link
$ cap mt_start

If all the commands ran succesfully go to myapp.mydomain.com and view your site! Now open myapp/public/index.html (the default ruby splash page) and change the header <h1> from ‘Welcome aboard’ to ‘Welcome to Capistrano Deployment on MT’ save the file and do a svn commit

$ svn commit -m="welcome page header change"
$ svn update

then with your update safely in the repository you just do ‘cap deploy’

$ cap deploy

Then go check your site and see the change! Any time you make an update you want to push live commit it to subversion and then cap deploy, That’s it!

Digg! submit MT GS RoR A-Z: The complete guide to Rails on Media Temple’s Grid Server to stumbleupon.com submit MT GS RoR A-Z: The complete guide to Rails on Media Temple’s Grid Server to del.icio.us submit MT GS RoR A-Z: The complete guide to Rails on Media Temple’s Grid Server to reddit.com Like this post? subscribe to the feed.

October 12, 2006

Media Temple Tames the Beast - New Ruby on Rails Hosting Service with Mongrel

Filed under: Cool Shise, Mongrel, Ruby on Rails Alastair @ 11:48 pm

Media Temple (gs)

For a long time deployment has been the giant stinky Grey elephant in the beautiful Ruby colored room. Rails makes developing an app a joy but for many, including me, deployment has been a bit of a nightmare. If you wanted shared hosting you went with folks who seemingly built their Rails set up by the seat of their pants; only allowed production apps with no errors (yeah right), killed your apps (sans restart), had non-existent tech support, or worst of all a magical combination of all of the above (I think I’m still waiting for my Dreamhost activation letter). The other solution, which I opted for, was to roll your own hosting on a VPS or dedicated server which involved a lot of research, conflicting docs, and the horror that is FastCGI. Mongrel has saved my arse on the private server front, and now it will be the foundation of Rails hosting for Media Temple’s new Grid Server (gs).

Putting the dog in the box

Each (gs) account has the ability to create Rails Containers into which you install Rails, MySQL AND/or PostgreSQL bindings and of course Mongrel. You then create your Rails app ‘rails appname’, create a user for managing the app, generate a .htaccess file, create a sym link and um… that’s it! You can then start/stop/restart your app with ‘mtr start appname’.

That is by far the easiest Rails install I’ve ever done shared or otherwise. A lot of gems are installed already and if anything is missing you can install it. There’s also up to 1GB of dedicated RAM for Ruby Apps. I’ve been helping beta test the setup and my apps are running on the (gs) as fast if not faster than on my VPS server that Media Temple also hosts.

Bu wait there’s more… Capistrano support is baked right in.

What else do I get?

I mentioned you can choose between MySQL or PostgreSQL dbs, PHP4 or PHP5 (if you must), plans start with 50GB of storage space and 1TB of Bandwidth, multi-site hosting with unique users for each host (i.e. sales@site1.com and sales@site2.com won’t conflict) and the whole reason it’s called the grid - you can expand instantly in case of traffic emergencies. Last but not least 24/7 tech support online or by phone.

I know this sounds like they’re paying me (no, but if you sign up make sure to put ‘vixiom.net’ in the referral box). I’m excited because they’ve met or surpassed all my Rails hosting needs and I don’t even have to switch companies! A lot of my projects for smaller clients can now be hosted for a fraction of a VPS or dedicated server.

Thank you (mt)! With a special thanks to Nate for answering all my RoR questions.

*UPDATE* Here’s a coupon for 10% off

Here’s a shot of the new control panel:


Media Temple Control Panel

Digg! submit Media Temple Tames the Beast - New Ruby on Rails Hosting Service with Mongrel to stumbleupon.com submit Media Temple Tames the Beast - New Ruby on Rails Hosting Service with Mongrel to del.icio.us submit Media Temple Tames the Beast - New Ruby on Rails Hosting Service with Mongrel to reddit.com Like this post? subscribe to the feed.

Powered by WordPress