Installing Rails and Mongrel on a Shared Host

In some situations you may find yourself needing to install mongrel or other ruby gems in a shared environment and the documentation out there for taking on such an enterprise is quite lacking.

Today I went through the trouble and figured out how.

Installing Rubygems in a user directory

After following the Rubybems documentation, Installing RubyGems in a User Directory , I ran across a few caveats.

Assuming ruby is already installed on the server. We can install rubygems and create a gem repository in our own user dir. eg. /home/ducky

  • Create a directory to house your gems
mkdir -p rubygems/gemrepository
~/rubygems will contain the rubygems lib and bin (gem script) while ~/rubygems/gemrepository will hold the installed gems.
  • Export the path to the gem repository. This env var will be used when installing new gems
$ export GEM_HOME=/home/ducky/rubygems/gemrepository
  • Export a new ruby library path
$ export RUBYLIB=$RUBYLIB:/home/ducky/rubygems/lib/ruby/site_ruby/1.8
This is necessary for ruby to find and require require rubygems
  • Export Paths for Rubygems bin directories. The first bin directory is for rubygems scripts like gem. The second bin path is for gem scripts like rails, mongrel_rails, etc.
$ export PATH=$PATH:/home/ducky/rubygems/bin:/home/ducky/rubygems/gemrepository/bin
NOTE: If you want the above env variables saved, you will need to also place these commands in your .profile file or similar.
  • Finally, download rubygems to your home dir and install with the—prefix option
$ ruby setup.rb config --prefix=/home/ducky/rubygems
$ ruby setup.rb setup
$ ruby setup.rb install
Now you should be able to gem install most gems without problems.

Installing Rails

If all is well you should be able to install rails and its dependencies without issue.

$ gem install rails --include-dependencies

Installing Mongrel

Mongrel is a little trickier to install because during the process it will compile a C extention and attempt to set the owner and group of the shared object http11.so to root:wheel, which we obviously dont have sufficient permissions to do (otherwise we wouldnt be going through all this trouble in the first place.), this causes the install to be incomplete and mongrel will not run.

To get around the above problem we need to first install then mongrel gem, then go into the gem repository to manually finish the install.

$ gem install mongrel
ruby extconf.rb install mongrel
checking for main() in -lc... yes
creating Makefile

...

make install
/usr/bin/install -c -o root -g wheel -m 0755 http11.so /home/ducky/rubygems/gemrepository/gems/mongrel-0.3.13.4/lib
*** Error code 71

Stop in /home/ducky/rubygems/gemrepository/gems/mongrel-0.3.13.4/ext/http11.

make clean
Successfully installed mongrel-0.3.13.4
Installing ri documentation for mongrel-0.3.13.4...
Installing RDoc documentation for mongrel-0.3.13.4...

It thinks everything went ok, hmmm? We need to hack the Makefile so it doesnt error out.

Change into ext/http11 dir of the unfinished mongrel gem

$ cd ~/rubygems/gemrepository/gems/mongrel-0.3.13.4/ext/http11

Doctor the Makefile so it doesnt attempt to change the owner and group of the http11.so

Before (find these lines in the Makefile)

INSTALL = /usr/bin/install -c -o root -g wheel
INSTALL_PROG = $(INSTALL) -m 0755
INSTALL_DATA = install  -o root -g wheel -m 444
After (change to this)

INSTALL = /usr/bin/install -c                 
INSTALL_PROG = $(INSTALL) -m 0755
INSTALL_DATA = install -m 444  

Now run make && make install within this dir to finish the install where it broke before.

$ make && make install
cc -fPIC -O2 -fno-strict-aliasing -pipe    -fPIC -I. -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I. -c http11.c
cc -fPIC -O2 -fno-strict-aliasing -pipe    -fPIC -I. -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I. -c tst_search.c
cc -fPIC -O2 -fno-strict-aliasing -pipe    -fPIC -I. -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I. -c tst_delete.c
cc -fPIC -O2 -fno-strict-aliasing -pipe    -fPIC -I. -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I. -c http11_parser.c
cc -fPIC -O2 -fno-strict-aliasing -pipe    -fPIC -I. -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I. -c tst_init.c
cc -fPIC -O2 -fno-strict-aliasing -pipe    -fPIC -I. -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I. -c tst_grow_node_free_list.c
cc -fPIC -O2 -fno-strict-aliasing -pipe    -fPIC -I. -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I. -c tst_insert.c
cc -fPIC -O2 -fno-strict-aliasing -pipe    -fPIC -I. -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I/usr/local/lib/ruby/1.8/i386-freebsd6 -I. -c tst_cleanup.c
cc -shared -Wl,-soname,http11.so -L'/usr/local/lib' -Wl,-R'/usr/local/lib' -o http11.so http11.o tst_search.o tst_delete.o http11_parser.o tst_init.o tst_grow_node_free_list.o tst_insert.o tst_cleanup.o  -Wl,-R -Wl,/usr/local/lib -L/usr/local/lib -L. -lruby18 -lc  -lcrypt -lm  -pthread  -lc

/usr/bin/install -c -m 0755 http11.so /home/ducky/rubygems/gemrepository/gems/mongrel-0.3.13.4/lib

Now http11.so is working and mongrel is ready to rock!

Start up your rails application with the mongrel_rails script and everything should be tickityboo.



About this entry


Comments

  1. Avatar

    prim8

    Posted: 4 days later:

    Mongrel clusters can be quite memory intensive. This may be a good way to piss off your host.

  2. Avatar

    Corban Brook

    Posted: 4 days later:

    If you needed a Mongrel cluster you would hardly be using a shared host in the first place.

About

    Buildingsky.net is comprised of Corban Brook and Maciek Adwent. We build experimental web applications.

    We are interested in computer science, ruby-lang, javascript, web technologies, audio synthesis, finance/economics.

Contact

Projects

Categories