Ruby on Rails
This article is going to compile information I've found in a few places just to let people know about this great application framework. Personally, I've just started with this thing, but it did take some searching to figure out how to get it installed. From what I hear, installing it is the hardest part of using it, and now after this, so many things are a breeze.
First, I'd like to point out the Slashdot posting on it. My biggest concern in this discussion is that it seems like many people think that in order to use Ruby their web host needs to have it preinstalled for them. Well, I am here to say that I got it done with my webhost, nicewebhost.biz (Disclaimer: I sell hosting here under a reseller account, therefore I don't have root access. I wish I did because I would make Ruby available to all my users. This is the next best thing I can do.) This will be exactly how I got it working at nicewebhost.biz, but will also show you some of the challenges you might have at your own webhosts when setting up Ruby and Rails.
I have to thank the information here on figuring out the primary step in installing Ruby without root access. Here is what I did then on nicewebhost. I had to pay $14 extra for the year to get SSH access. But even that added in, I think the total amount that my clients and I pay for hosting is still inexpensive. Login to you SSH account.
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.2.tar.gz
tar xvfz ruby-1.8.2.tar.gz
cd ~
HOMEDIR=`pwd`
cd ~/www/usr/src/ruby/ruby-1.8.2
./configure --prefix=$HOMEDIR/usr
make
make install
PATH=$PATH:~/www/usr/bin
Ok now the Ruby part is over. Its time to install Rails. Gem is a cool tool to manage third party software for Ruby (I am starting to tear I thinking about how much time I spend with classpaths and Java jar files all day).
cd ~/www/usr/src
wget http://rubyforge.org/frs/download.php/2412/rubygems-0.8.4.tgz
tar xvfz rubygems-0.8.4.tgz
cd rubygems-0.8.4
ruby setup.rb
That was it, now to install rails.
gem install rails
Answer Y to installing activerecord and actionpack.
Ok, now I am going to go through some of the instructions at the Rails wiki site. Lets create an application directory.
rails /home/www/firstapp
Your rails application is now seeded with all sorts of files, with the correct permissions . We have to change the default path to Ruby in those files.
cd firstapp/public
ruby -i -pe 'gsub!("#!/usr/local/bin/ruby", "#!/home/www/usr/bin")' public/dispatch.* script/*
Rails uses an Apache .htaccess file in the firstapp/public directory to route web requests. With nicewebhost.biz you need to use the Control Panel and password protect the public directory to get the .htaccess file working. Open up your Control Panel and go to the "Site Manager" section and click on "Password Protected Areas". Password protect the /home/www/firstapp/public directory for a single user. Don't worry, the .htaccess file will override the protection you are setting here, but nicewebhost requires the directory to have some default password protection in place first. So password protect the new rails application directory (for example: /www/firstapp/public) with a user of your choice. We are almost done. The .htaccess file needs one tweak to make it good at nicewebhost. They don't allow Options in the .htaccess file, since the necessary one are already configured by default. So run
cd /www//firstapp/public
ruby -i -pe 'gsub!("Options +FollowSymLinks +ExecCGI", "")' .htaccess
Now open a web browser and go to your site (http://www. your domainname.com/firstapp/public). And you should get your Congratulations screen! Now there is just one more step to allow for the default .htaccess to work out for you. You should access your new rails application from a sub domain. I am sure people can figure out some other things with the .htaccess file, but I am new to this, and I found that using a subdomain pointing to the public directory worked great.
Go to the Control Panel again.
Go to "Site Manager" -> "Subdomain Manager"
Add your subdomain and have the path point to /www/firstapp/public
Now if you continue on and follow the instructions in some of the tutorials (I will assume that most of you here can figure out the MySQL stuff with phpMyAdmin that is also in the Control Panel. If not just let me know.) everything should work out perfectly. Just access your application at your new sub domain:
http://subdomain.yourdomainname.com
Have fun with Rails. It looks like a fun ride. I made certain assumptions about everyone's comfortablity with MySQL and other things. If you have any further questions about this article or nicewebhost.biz please don't hesitate to send me an email at nate@inventric.com.
First, I'd like to point out the Slashdot posting on it. My biggest concern in this discussion is that it seems like many people think that in order to use Ruby their web host needs to have it preinstalled for them. Well, I am here to say that I got it done with my webhost, nicewebhost.biz (Disclaimer: I sell hosting here under a reseller account, therefore I don't have root access. I wish I did because I would make Ruby available to all my users. This is the next best thing I can do.) This will be exactly how I got it working at nicewebhost.biz, but will also show you some of the challenges you might have at your own webhosts when setting up Ruby and Rails.
I have to thank the information here on figuring out the primary step in installing Ruby without root access. Here is what I did then on nicewebhost. I had to pay $14 extra for the year to get SSH access. But even that added in, I think the total amount that my clients and I pay for hosting is still inexpensive. Login to you SSH account.
mkdir -p ~/www/usr/src/ruby
cd ~/www/usr/src/rubywget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.2.tar.gz
tar xvfz ruby-1.8.2.tar.gz
cd ~
HOMEDIR=`pwd`
cd ~/www/usr/src/ruby/ruby-1.8.2
./configure --prefix=$HOMEDIR/usr
make
make install
PATH=$PATH:~/www/usr/bin
Ok now the Ruby part is over. Its time to install Rails. Gem is a cool tool to manage third party software for Ruby (I am starting to tear I thinking about how much time I spend with classpaths and Java jar files all day).
cd ~/www/usr/src
wget http://rubyforge.org/frs/download.php/2412/rubygems-0.8.4.tgz
tar xvfz rubygems-0.8.4.tgz
cd rubygems-0.8.4
ruby setup.rb
That was it, now to install rails.
gem install rails
Answer Y to installing activerecord and actionpack.
Ok, now I am going to go through some of the instructions at the Rails wiki site. Lets create an application directory.
rails /home/www/
Your rails application is now seeded with all sorts of files, with the correct permissions . We have to change the default path to Ruby in those files.
cd firstapp/public
ruby -i -pe 'gsub!("#!/usr/local/bin/ruby", "#!/home/www/usr/bin")' public/dispatch.* script/*
Rails uses an Apache .htaccess file in the firstapp/public directory to route web requests. With nicewebhost.biz you need to use the Control Panel and password protect the public directory to get the .htaccess file working.
cd
Now open a web browser and go to your site (http://www.
Go to the Control Panel again.
Go to "Site Manager" -> "Subdomain Manager"
Add your subdomain and have the path point to /www
Now if you continue on and follow the instructions in some of the tutorials (I will assume that most of you here can figure out the MySQL stuff with phpMyAdmin that is also in the Control Panel. If not just let me know.) everything should work out perfectly. Just access your application at your new sub domain:
http://subdomain.yourdomainname.com
Have fun with Rails. It looks like a fun ride. I made certain assumptions about everyone's comfortablity with MySQL and other things. If you have any further questions about this article or nicewebhost.biz please don't hesitate to send me an email at nate@inventric.com.

3 Comments:
thanks, this was helpful. I had to flip-flop the PATH so that my binaries are used instead of the default ruby version installed in my server (Dreamhost), changing PATH=$PATH:~/www/usr/bin to PATH=~/www/usr/bin:$PATH
You're welcome. Thanks for the update!
Thanks, very helpful explanation. Got Rails up and running on a shared account at networkeleven.net in no time.
Post a Comment
<< Home