Ruby/Rails on unix.cs.tamu.edu

written by ben on September 1st, 2007 @ 01:42 PM

I wanted to host a ruby on rails website on my csnet account, but there were some problems. The server is running an older version of ruby without gems installed. Also, it looks like apache is not compiled with fastcgi. To get around this, I had to install ruby and gems locally, and proxy the requests to a mongrel server. There are a bunch of how-to’s on installing ruby/rails, but I ran into a few hiccups due csnet’s configuration. This guide is mostly gathered from here.

Step 0: Environment Setup

First off, ssh into your unix account. There’s information on how to do this over at cs helpdesk.

I’m used to the bash shell, but the default is tcsh. If you have no idea what difference is, I recommend switching to bash:

echo "exec bash --login" >> ~/.login

Log out and log back in; the prompt should have changed to something like bash-3.00. I recommend changing the prompt to something more usefull:

echo "PS1=\"\[\033[0;31m\][\u@\h \W]#\[\033[0m\] \"" >> ~/.bash_profile

Log in/out or source the .bash_profile file and the prompt should be updated.

Because we are building and executing everything locally, we need to add a few folders:

cd ~/
mkdir -pv soft run www log
cd ~/run
mkdir -pv bin etc include lib man share

Next, we need to set the RUN variable and update PATH:

cat >>${HOME}/.bashrc <<eof
export RUN="\${HOME}/run"

export PATH="\${RUN}/bin:\${PATH}"

export LD_LIBRARY_PATH=\${RUN}/lib:\${LD_LIBRARY_PATH}
export LD_RUN_PATH=\${RUN}/lib:\${LD_RUN_PATH}
eof

echo "source ~/.bashrc" >> ${HOME}/.bash_profile

Step 1: Install Readline

Ruby requires Readline, so we need to install it locally before compiling ruby:

cd ${HOME}/soft
wget ftp://ftp.cwru.edu/pub/bash/readline-5.2.tar.gz
tar xvzf readline-5.2.tar.gz
cd readline-5.2

./configure --prefix=${RUN}
make && make install

Step 2: Install Ruby

Download, compile, and install ruby locally:

cd ${HOME}/soft
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.6.tar.gz
tar xvzf ruby-1.8.6.tar.gz
cd ruby-1.8.6
./configure --prefix=${RUN} --with-readline-dir=${RUN}
make && make install

This will tell ruby to use use the local libs folders:

cat >> ${HOME}/.bashrc <<eof
# ruby library search path
export RUBYLIB=\${RUN}/lib/ruby:\${RUN}/lib/rubyext
eof

Logout/in then make sure ruby is pointing to ~/run/bin/ruby and is the version you installed (1.8.6):

which ruby && ruby -v

It should print something like:

/user/brb1763/run/bin/ruby
ruby 1.8.6 (2007-03-13 patchlevel 0) [sparc-solaris2.8]

Step 3: Install RubyGems

Download and install rubygems:

cd ${HOME}/soft
wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
tar xzvf rubygems-0.9.4.tgz
cd rubygems-0.9.4
ruby setup.rb config --prefix=$RUN
ruby setup.rb setup
ruby setup.rb install

Verify rubygems is installed:

which gem && gem -v

You should see:

/user/brb1763/run/bin/gem
0.9.4

Step 4: Install Rails

Install rails and mongrel:

gem install rails mongrel --no-rdoc --no-ri -y
If you are prompted to choose a gem, select the ones that end with (ruby).

Verify rails is installed:

which rails && rails -v

That should print:

/user/brb1763/run/bin/rails
Rails 1.2.3

Step 5: Create a Test Site

Create a test rails site in your www dir:

cd ~/www
rails test_site

Start a mongrel server to server your site:

cd ~/www/test_site
mongrel_rails start -d -p 3042 -l ~/log/mongrel.log

The port number (3042 in this case) should be a random but unique port number. If you are local or have a vpn connection, browse to http://unix.cs.tamu.edu:<your port number>/, it should serve the ruby on rails placeholder page.

Step 6: Proxy Requests to Your Mongrel Server

Set the mod_proxy stuff in your .htaccess file:

mkdir -pv ${HOME}/web_home/test_site
cd ${HOME}/web_home/test_site
cat >> .htaccess <<eof
RewriteEngine   on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://unix.cs.tamu.edu:<your port number>/$1 [P]
eof
chmod 644 .htaccess

Don’t forget to set the port number. Browse to http://students.cs.tamu.edu/<your username>/test_site/, if you see the placeholder page, you’re good to go.

Comments are closed