PDA

View Full Version : [HOWTO] Ruby on Rails


Adam
05-20-2005, 10:12 AM
http://enterprise.myriadnetwork.com/%7Emyriad/htimg/rails_logo.gif

Welcome!

This tutorial is going to go a bit in depth on how one would get Ruby on Rails up and running properly.

To best summarize what Rails is, I am going to extract a quote straight from there website.

Rails is a full-stack, open-source web framework in Ruby for writing real-world applications with joy and less code than most frameworks spend doing XML sit-ups

For those of you that are wondering what ruby has to do with rails, please refer to the quote below.

Ruby is a pure object-oriented programming language with a super clean syntax that makes programming elegant and fun.

Now that we know what these two are made for we can get ahead with the install and implementation of both of them.


First thing that we will need to do is go ahead and download the Ruby application. This is basically the platform that Rails will run off of.

Currently if you are planning on using version 0.10 or later of Rails then you will need to download Ruby v1.8.2 or newer.

To do this you will need to issue the following command within your SSH window.

wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.2.tar.gz

Once the package has downloaded you will need to extract it using tarzxvf ruby-1.8.2.tar.gz. The files will now be extracted into a directory called

ruby-1.8.2. You will now need to change to that directory.

The next step in getting Ruby running would be to configure it. To do this one would need to run ./configure while being in the ruby-1.8.2 directory.

This takes about one minute to complete. If it has complete without any errors then it is now time to move on.

We will now need to make the application by running the 'make' command in the current directory. This can take anywhere from 1-5 minutes to

complete. If this has completed properly then you will see something that says "Test Succeeded", we have included a screen capture below of what should be seen.

http://enterprise.myriadnetwork.com/%7Emyriad/htimg/ror1.png

Now it is time to get the application installed, you will need to run 'make install' to do so. This process is quite fast and should finish without error.

Once that has been completed, we can move on to getting Rails installed.

Rails uses extensions called "Gems". These are easily installed via command line but need a program called RubyGems before this can be done.

You will need to run the following commands to get RubyGems installed so that we can get Rails installed on the machine.

First we need to download RubyGems using the following command.

wget http://rubyforge.org/frs/download.php/3700/rubygems-0.8.10.tgz

Next we need to change to the RubyGems directory:

cd rubygems-0.8.10

Now we will need to setup RubyGems, we will do this using the following command:

ruby setup.rb

You should see the following screen stating that it has installed properly.

http://enterprise.myriadnetwork.com/%7Emyriad/htimg/ror2.png

Now it is finally time to move on and get Rails installed. We will be doing this via the RubyGems application that we just installed, but first we need to update by running:

gem update

This will update any of the gem source that is currently installed. Once the update has been completed we can go ahead and install Rails. This is done simply via Gem by running:

gem install rails

When you are installing Rails you may be prompted to install a few dependencies that are needed as well, I would highly suggest choosing the Y option and installing these dependencies to avoid any problems down the line when you are ready to use these applications.

Below I have included a screen capture of what the install looked like for me.

http://enterprise.myriadnetwork.com/%7Emyriad/htimg/ror3.png

Now you are ready to create your application. This is done rather simply through Rails using one command.

You need to make sure that the directory that you are using is accessible via the Webserver that you are using, normally it would be best to use a directory in your /home tree for this but my example will be with a different directory.

To get this setup in my directory I simply ran:

rails /var/www/html/myapp

Now that you have this properly setup you will need to have your Webserver point to the folder named 'public' by default when your webpage is visited.

Below I have included a sample httpd.conf DocumentRoot entry that can be used.

Please Note: In order for this to run properly, mod_rewrite is going to need to be installed.

<VirtualHost *:80>
ServerName rails
DocumentRoot /path/application/public/
ErrorLog /path/application/log/apache.log

<Directory /path/application/public/>
Options ExecCGI FollowSymLinks
AddHandler cgi-script .cgi
AllowOverride all
Order allow,deny
Allow from all

</Directory>
</VirtualHost>


This installed all of the needed files in my directory.


You have now successfully installed Ruby on Rails. Now that this is done there is alot more that you can do with this application, there is various different resources around the internet that more information can be found on but I am going to go ahead and provide you with the links that I feel are most important.

FastCGI

I would suggest setting up FastCGI, this is used to speed up your applications and is integrated into Apache once you install it. More information regarding that can be found here. http://wiki.rubyonrails.com/rails/show/FastCGI

How-To's

The Ruby on Rails website is also full of How-To's for various things to do with this application. For anyone using this application I would highly suggest visiting the page below

http://wiki.rubyonrails.com/rails/show/Howtos

FastCGI Implementation & Apache HTTPD Implementation

Below is an excellent URL thast will show how to implement FCGI with Apache.

http://wiki.rubyonrails.com/rails/show/Fast+CGI+and+Apache2+for+Red+Hat+Linux+9

If you have not noticed all of the URL's I have provided you are from one page, this page has a vast array of documentation and should be looked at by anyone interested in using Ruby on Rails.

http://wiki.rubyonrails.com

Please note, the ROR logo is not property of Myriad Network and is only being used in this tutorial.

If you have any questions, please feel free to let us know, we would be glad to help you out.


Fast-track your Web apps with Ruby on Rails http://www-128.ibm.com/developerworks/linux/library/l-rubyrails/?ca=dgr-lnxw06RubyRails

Jeff
06-24-2006, 08:22 AM
From Zero To ROR In Minutes


Here's an install script I just whipped up for Adam's tutorial. This will install ROR on a Myriad Network VDS. It has been tested and confirmed to work great with the following packages:

ruby-1.8.4
rubygems-0.8.11


Note that this will take care of all the steps in the tutorial above up to the point where Adam states "Now you are ready to create your application. This is done rather simply through Rails using one command" (just after his last screenshot).



#!/bin/sh

# 06/24/06 - Ruby On Rails Installer

PATH=/bin:/usr/bin


echo "Welcome to the ROR installer."
echo "You will need to enter your root password several times during this installation."
echo


# uid check
if [ "$UID" == "0" ] ; then
echo "You do not yet need to be root. Exiting."
exit
fi


# wget sanity check
if [ -e "/usr/bin/wget" ] ; then
echo "[+] FOUND: /usr/bin/wget"
else
echo "[-] I was not able to find /usr/sbin/wget. Exiting."
exit
fi


cd ~


# create the second half of the setup script
echo "Creating the ruby_setup2.sh script"
umask 0077
cat>ruby_setup2.sh<<EOF
#!/bin/sh
PATH=/usr/bin:/usr/local/bin
ruby $HOME/rubygems-0.8.11/setup.rb
gem update
yes Y | gem install rails
EOF
umask 0022


if [ -e "$HOME/ruby_setup2.sh" ] ; then
echo "[+] SUCCESS: $HOME/ruby_setup2.sh"
else
echo "[-] I was not able to create $HOME/ruby_setup2.sh"
exit
fi


# download and install Ruby
echo "[+] downloading Ruby"
wget http://rubyforge.org/frs/download.php/7858/ruby-1.8.4.tar.gz
echo "[+] unpacking ruby"
tar zxvf ruby-1.8.4.tar.gz
cd ruby-1.8.4
echo "[+] running ./configure"
./configure
echo "[+] running \"make\""
make
echo "Please enter your root password when prompted."
su -c "make install"
echo "[+] running \"make install\""


cd ~


# download and install Rails
echo "[+]downloading Rails"
wget http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
echo "[+] unpacking rails"
tar zxvf rubygems-0.8.11.tgz
cd rubygems-0.8.11
echo
echo
echo
echo "Please enter your root password when prompted."
su -c "sh $HOME/ruby_setup2.sh"


cd ~


# cleanup
rm -fr ruby-1.8.4
rm -f ruby-1.8.4.tar.gz
rm -fr rubygems-0.8.11
rm -f rubygems-0.8.11.tgz
rm -f ruby_setup2.sh
echo "[+] done!"



To use this, simply create a shell script, called anything you'd like, and make it executable. For example:


$ cd ~
$ cat>setup.sh
(paste the contents here, then hit enter so you end on a blank line)
^D (control+D)
$ chmod 700 setup.sh
$ ./setup.sh


Create and run this as a non root user, and you will have a near unattended ROR install, only requiring interaction for entering the root password twice.

dsynthuhsize
08-11-2006, 12:35 PM
Wow, this is really great....

Thanks Adam and Jeff for the great tools and tips....

Jeff
08-11-2006, 12:51 PM
I know I read something recently about cPanel creating a ruby install script ( /scripts/installruby ), but I don't remember where I saw it. I searched their forums at forums.cpanel.net for "installruby" and came up empty handed. I should note that when this script is incorporated into cPanel, it would probably be easiest to simply do the following:

1. Log into your VDS via ssh
2. su to root
3. At the command line, type: /scripts/installruby

I imagine that would be the entire process, as the /scripts/install* files typically just need to be ran once, and then that package will be installed. I will post more information here as I learn more about it.