Ruby on Rails

Notes for setting up RoR for multiuser setup in Fedora 8 using Apache.

What I installed

I used yum to install ruby, ruby-libs , ruby-irb, ruby-rdoc, ruby-ri, rubygems, ruby-devel, rubygem-fastthread, ruby-mysql, ruby-docs, ruby-bsearch, & ruby-bdb.

Then I used gem (from rubygems) to install rails-toolkit, which is a bundle of trails and things commonly used in a rails setting.

AllowOverride

You must AllowOverride All. You can't set AllowOveride in DirectoryMatch or a Directory with a wildcard, so you have to set up a Directory section in your Apache config for a higher level dir, like /home, and set AllowOverride All there.

To see if the server is reading your .htaccess files at all, put garbage in the top. If the server is reading them, it will blow an error, otherwise it will serve the content as though the .htaccess file was not there.

Where to put it?

My username is 'dmartin' and I'm calling my project 'ror'. I went to my home dir and ran rails ror -d mysql. Then I made a link from ~dmartin/ror/public to ~dmartin/public_html/ror. Make sure your apache config allows FollowSymLinks or similar.

The bit that looks like '-d mysql' specifies that I'm using mysql and sets up default config stuff in a reasonable way for this. Set this correctly for your environment.

.htaccess

Rails installs a default .htaccess file in the 'public' dir. Look for the RewriteRule bits and read the comments about RewriteBase. I'm not using an Alias per say, but the affect is the same, so I have to add a line with RewriteBase /~dmartin/ror to the .htaccess file above the RewriteRule entries.

ExecCGI

For some reason, the 'Options +ExecCGI' line in .htaccess isn't working. I added ExecCGI to the options for user home dirs. This could cause some other wierdness, but I'll cross that bridge when I come to it.

Database

I'm going to set up a mysql account called 'dmartin' with a real password. I need to edit ~/ror/config/database.yml to contain that information.

suexec

Apparently, apache is trying to use suexec to run this. That's not what I want (yet..), so I renamed /usr/sbin/suexec to /usr/sbin/suexec.renamed

file permissions

If you're not using suexec or similer, all your files need to be readable by anyone. If your umask is prohibitive, evey time you use a tool like script/generate, you'll get a bunch of files that the web server can't read.

Names Matter

I've gotten all confused making my demo app. First I tried to copy an example from a tutorial, but I'm such a bad speller the whole thing went wrong. So, I tried something really easy to spell: "fish". BZZZZ!! The plural and singular of fish is the same! This apparently confused the crap out of RoR. So, here's what I think I've learned:

  1. use a name that's got simple singular/plural forms
  2. use the plural as the name of your db table
  3. use the singular as your "model" when scafolding

For example, if your db table is 'dogs' and dogs have a name property, you might scaffold with ruby script/generate scaffold dog name:varchar

FastCGI

FastCGI can use wrappers like cgiwrap or suexec, so I think I'll try and make it work!

Must install

suExec Yes!

Okay, I'm ready for suexec.

The main problem is suexec has a setting called 'userdir' that prohibits execution of files outside the 'userdir' inside a user's home dir. By default it's set to 'public_html'. Unfortunately, my dispatcher.cgi lives in /home/username/ror/public, not /home/username/public_html/. So, I decided to rebuild suexec with a more permission userdir. I set it to '/' hoping that would mean /home/userdir/, not just '/', which would be basically turning off the userdir check.

Maybe there's a way to make /home/username/public_html/ror a copy of /home/username/ror/public instead of a link. Then this wouldn't be a problem....

Anyhway, here's what I did. Pay special attention to the make lines below, they save you having to compile/install all of apache.

I downloaded the source to apache, and made a file called runConfig.suexec.pl. It looks like this:

  ./configure \
  --sbindir=/usr/sbin \
  --enable-suexec       \
  --with-suexec-bin=/usr/sbin/suexec \
  --with-suexec-caller=apache \
  --with-suexec-userdir=/  \
  --with-suexec-docroot=/home/webmaster/webroot \
  --with-suexec-uidmin=500  \
  --with-suexec-gidmin=500  \
  --with-suexec-logfile=/var/log/httpd/suexec.log  \
  --with-suexec-safepath=/usr/local/bin:/usr/bin:/bin \
  --with-suexec-umask=0022  \

Then I run this line:

  make clean && ./runConfigure.suexec.sh && make suexec && sudo make install-suexec

Oh, that was silly

It's actually pretty easy to move the 'public dir of your RoR stuff into public_html instead of just making a link. The only thing you have to do is edit the dispatcher script so the like which requires the config/environment file has a hard-coded absolute path.

E.G.

require File.dirname(FILE) + "/../config/environment"

becomes

require "/home/username/ror/config/environment"

easy!

And then to keep from confusing yourself with two copies of 'public', erase the one in your ror hierarchy and make it a link to the one in your public_html dir.


CategoryNotes

Ruby_on_Rails (last edited 2008-11-17 23:27:17 by dmartin)