Installing eRuby on Shared Hosting
10 Jun 2005Now that we've got Ruby installed, we can use it to write CGI scripts. But that is so 1995, isn' t there a better way to use Ruby to create web sites? Of course there is, and the first step is eRuby. eRuby interprets Ruby code that is embedded in a text file. Our interest is embedding Ruby code to a HTML file, much like Microsoft's Active Server Pages, Sun's Java Server Pages, and Zend's PHP.
Just like installing Ruby, this is surprisingly easy to do, as we simply enter these commands in at the shell:
We've installed, compiled, and copied the eruby
executable file to our site's cgi-bin
directory. Our site is now ready to use the executable to parse our HTML files for Ruby code and execute it. To do this, we need to associate our files with the CGI executable. Parsing our files for Ruby code does add some overhead, so we probably don't want to parse every single file, so we'll associate the file extension .rhtml
with eruby
. We make this association in the .htaccess
file in the public_html
directory by adding these lines:
If you don't have an .htaccess
file in your public_html
directory then simply create one. Let's test this! Create a new file in your public_html
directory named hello.rhtml
. The file should include the following lines:
When you browse to the file you will see a message that displays Hello Hello Hello Hello Hello Ruby!
then you have officially installed eRuby, congratulations.