Welcome Guest | Login

A Custom Rails App Installation Example

Since the client I just did this for was game to let me post the process - and because it was a pretty textbook case - we thought it would be nice to share the following (with generic names, of course):  

To begin, after I saw the zip file uploaded to the client's app I performed the following commands
[~]# unzip railsapp.zip
[~]# cd railsapp
[~/railsapp]# cd config
[~/railsapp/config]# vi database.yml
I made sure the database.yml file consisted only of the following:
production:
 adapter: mysql
 database: username_db
 username: username_dbuser
 password: thepassword
Then in the environment.rb file I made sure this line was uncommented
ENV['RAILS_ENV'] ||= 'production'
Then jumping over to the routes.rb I set:
map.connect '', :controller => "the_default_controller"
At this point the config folder was set.  I then jumped into their cPanel and created the mySQL database 'db', created the user and password, then assigned the user to the database (this last step is important!)

Double checking that ~/railsapp/db/schema.sql was there I ran a quick:
[~/railsapp]# rake db:migrate RAILS_ENV='production'
which seemed to work nicely.

Moving on to the public folder I made sure the Shebang line of dispatch.rb and dispatch.fcgi files were set to #!/usr/local/bin/ruby - then I ran a quick
[~/railsapp/public]# chmod 755 disp* 
which set the right permissions for the dispatchers.

Then I renamed the index.html file to index.html.backup
[~/railsapp/public]# mv index.html index.html.backup
and made sure the AddHandler for fastcgi was commented out of the ~/railsapp/public/.htaccess
#AddHandler fastcgi-script .fcgi
...which is needed because we're running mod_fcgid on the clients server which is already 'Handled' in the httpd.conf file.  

And so the last step is just to make the symlink in root for public_html
[~]# mv public_html public_html_backup
[~]# ln -s ~/railsapp/public ~/public_html
Then browsing to the client's url showed the app fire up correctly on FastCGI  

Cheers,

~William

2006-12-20 02:18 PM

Thanks again, William.  I especially liked the line about the textbook case.  :)

So first, does this setup use Mongrel or Lighttpd?

How about Capistrano and Subversion?  Everything I read about RoR talks about Cap and Subversion.  But I am having a terrible time trying to figure out how to use them with RoR.  Being told to use a wrench isn't very helpful, when you don't know what a bolt is or that the nut should be threaded onto it and turned with the wrench.  Are they supposed to be on one's desktop? Or are those just automatically available on a server or maybe on this server?  Are they as necessary as it sounds when reading?  Or am I just showing my incredibly new ruby-ness?

If it seems that I am immediately stepping outside the bounds of application deployment, well, my only defense is that they sure kept popping up when I tried to do my own deployment with other hosting services.

Thanks,
Jee
PS: I really like your new RoR forum!

2006-12-20 02:57 PM

Life is too short for this ...
OK - good questions.

First of all - your app was setup on FastCGI, which doesn't require persistent static memory like Mongrel does.  

To help clarify things let's go over some definitions tailored for our purposes:

Apache: Robust and popular web server

Mongrel: Super quick web server that was built for ruby applications

LightTPD: A 'light' and fast web server that folks like YouTube and Wikipedia use

FastCGI: A server-independent CGI extension that allows in-memory caching of Rails apps.  That is, its an "application server" rather than a "web server"

Subversion: A version control system that you (and your development team) can use to keep track of changes to your code.  

Capistrano: Formerly called SwitchTower - is a tool that I don't want to underplay.  It is used most commonly to 'deploy Rails apps' but it really is a powerful way to run shell scripts and upload files simultaneously on multiple servers.    



So - Rails people like to use Capistrano to interact with their subversion repositories (hosted at home or afar) to automate their deployment tasks.  But you don't need subversion to use Capistrano. Capistrano can work with pretty much anything. But heck you really don't need to use Capistrano, it just saves you time in the long run when you're scaling way up...

Also, to clarify the server stuff.  We offer hosting on apache servers and offer to proxy requests to Mongrel servers that are running behind the scenes on dedicated ports that we assign to clients.  

Let me just give you a list of scenarios and maybe this will make more sense:

  1. Apache serving up html pages
  2. Apache interacting with php to serve .php pages
  3. Apache interacting with CGI to serve up Rails apps.  
  4. Apache interacting with FastCGI to serve up Rails apps.  
  5. Apache proxying requests to a mongrel server
  6. Apache proxying requests to a LightTPD server that uses FastCGI
You can essentially run through all of these scenarios with LightTPD as the front-end server, too.  But you can't with Mongrel really, because it was designed to serve up Ruby applications.  

Is this helping at all?  I'll stop here for questions.

Cheers,

~William

2006-12-20 03:36 PM

Ok, yes, it helps.  I would like to paraphrase and apply this information to my case.  Please correct me if I am heading in the wrong direction.

Currently, my app is using fastcgi and apache.  When development finishes and the site is ready to go live, will fastcgi and apache be appropriately speedy?  If not, are there steps that can be taken at that time to improve speed of the site?

I don't think I am interested in Subversion at this time.  I develop alone and have my own 'system' for retaining previous versions of a given project.  If I choose to start using Subversion later, that is do-able also, correct?

I am beginning to wonder if part of my problem is that I usually develop sites using dHTML and PHP.  I archive the work I did yesterday and then download the live site.  As I make changes, I upload and view the changes.  If they work, yippy skippy, if not, I make more changes, upload and view again.  Essentially, I do all my work in tiny increments and in a live environment.  If something doesn't work it gets fixed immediately.

Ruby on Rails seems to require a different mindset.  I will try to sum up.  I make a larger change, do all development for that change on my desktop, then follow your instructions above starting with the zip file?  Can't I just upload the /app dir (or some other section) when I get to a good spot in development?

If I do that, I am not taking advantage of the db:migrate features, am I?  Are there other RoR features I will be losing out on?

Does learning and using Capistrano make this all less intimidating?

If I am losing sight of the Ruby on Rails mindset, please help me get back on track!  :)

Thanks,
Jee

2006-12-20 06:51 PM

Life is too short for this ...
FastCGI can go a long way - but for the most speed you'll want to eventually get on mongrel(s) - which can be added no problem down the road.

Subversion later is no problem, too.

Yes you can upload files like you're used to.  There is no problem with doing this.  You just may need to stop/restart mongrels and/or fastcgi processes so the changes to your models/controllers get picked up.

There are tons of Ruby on Rails features that you may be 'missing out on' - sure - migrations are awesome....but really whatever works for you is best.  

Learning migrations and Capistrano for deployment is a *very* good idea, however.  So I'd recommend it.  Come back and post questions!  

All the best,  

~William

2006-12-21 05:55 AM

William,
Just a quick note to let you know that I just updated my app successfully!!  I cannot thank you enough for the clear information and the patience!  I may live through this contract yet.

Best wishes for a great new year.
:)
Jee

2006-12-31 04:53 PM

Life is too short for this ...
You too Jee, let us know if you have any other questions, anytime.  

2006-12-31 04:55 PM

William,
Earlier, you said I would need to restart cgi processes if I only uploaded part of the my app.
How do I do that?
Jee

2007-01-16 07:57 PM

Life is too short for this ...
Uh oh,
I've messed something up.  I uploaded the latest version of my app, attempted to follow the instructions above and am getting a blank page and nothing in the app logs.

I look forward to hearing from you!
Jee

2007-01-16 08:25 PM

Life is too short for this ...
Hi Jee - if you're running fastcgi then you need to do a 'killall dispatch.fcgi' or with mongrel a 'mongrel_rails restart' or with a mongrel cluster 'mongrel_rails cluster::restart' - I'll take a look at your account.

2007-01-16 11:52 PM

Hi there- ok your site is back up.  You needed to add the '.fcgi' to your dispatch rewrite in your .htaccess :)  

2007-01-16 11:59 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up.