Getting apache2 to serve eRuby files on MacOSX 10.5

Like many web developer, I heard of Ruby via Rails.
Rails make wonders. That’s true.
But it fits a really particular type of development. Application-oriented developments.
So Rails is not really for me (yet), but what of Ruby ?
Digging a little, reading about a lot, using prototype (rubyesque JS library), Ruby seems a really good choice for web dev.
So I decided to give it a try.
Being on MacOSX 10.5, I needed an install.
Browsing google helps a lot, but resources are a little sparse.
One more won’t hurt !

Source is mainly maymay.net
(if you’re interested in Rails, hivelogic.com is the place)

I will try to be a little less verbose than maymay, though.

You’ll need:

Steps are :

  1. Install eruby
  2. Alter Apache Conf

Where maymay advise to install MacPort to get eruby, I got it directly at the source: modruby.

Create a working dir where you please, download, expand, configure, make, make install, clean your mess :


ralovely$ mkdir ~/Desktop/wrkdir/
ralovely$ cd ~/Desktop/wrkdir/
ralovely$ curl -O http://www.modruby.org/archive/eruby-1.0.5.tar.gz
ralovely$ tar -xzf eruby-1.0.5.tar.gz
ralovely$ cd eruby-1.0.5/
ralovely$ ./configure.rb
ralovely$ make
ralovely$ sudo make install
ralovely$ sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/eruby /usr/local/bin/eruby

That’s it you have a working eruby. You can check with:
ralovely$ eruby –version

or:

ralovely$ echo 'Hello world! The time is now <%= Time.now %>.' > test.rhtml
ralovely$ eruby test.html

You should see a Hello World with current date and time.

now you can clean a little:


ralovely$ cd ../../
ralovely$ rm -R ./wrkdir/

Now to step 2: mod apache2 conf file.
maymay’s mod is based on a Tiger Mac. Leopard comes with apache2, and the mod is a little different.
First, we link our freshly installed eruby to the web server CGI directory

ralovely$ ln -s /usr/local/bin/eruby /Library/WebServer/CGI-Executables/eruby

Last, edit your httpd.conf file with your favorite editor (mine is pico)
but not without a little backup before:

ralovely$ cd /etc/apache2/
ralovely$ sudo cp httpd.conf httpd.conf.BAK
ralovely$ sudo pico httpd.conf

In there:
First, we allow symlink for CGI :
change:


<Directory “/Library/WebServer/CGI-Executables”>
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

To:

<Directory “/Library/WebServer/CGI-Executables”>
AllowOverride None
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>

then, look for the <IfModule mime_module> block and add

AddHandler rubypage .erb .rhtml
Action rubypage /cgi-bin/eruby

Save and exit. (ctrl-X then Y on Pico).

Reload your apache:

ralovely$ sudo apachectl graceful

You should now be able to serve .rhtml or .erb files on your MacOSX 10.5

MacOSX Server version should not be very different. I’ll test later.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

Neat. Thanks for posting the instructions for Mac OS X 10.5. I’ve just now gotten Leopard but haven’t had time to test out eRuby or update my post.

I was verbose in an attempt to explain the intricacies to newbies—clearly, not all people need the extra explanation.

@Meitar Moscovitz
“I was verbose in an attempt to explain the intricacies to newbies—clearly, not all people need the extra explanation.”
I am not because I’m lazy…

Leave a comment