Today I set up a Mac OS X Server (Tiger) box to run rails applications with fastcgi, the stock apache (1.3.33) and the mysql gem. So these are the exact steps I took...
Update 25/09/06 : I'm now pretty much converted to using Darwin Ports for my ruby/rails/lighttpd/apache2 installation. It seems easier to get a capistrano-friendly fastcgi setup working with lighttpd than apache (although that's probably more to do with my bad understanding of apache). The trick with Darwin Ports is to make sure that nothing ever uses the original apple ruby installation (especially remote Capistrano tasks). This is an easy problem to solve once you know how.
Firstly you should edit the PATH declaration in /etc/profile so it looks like this:
PATH="/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
This will update all users default paths to see at Darwin Ports installed binaries.
Then there's the fix to get Capistrano's remote tasks to work with the Darwin Ports environment. These tasks execute the command directly via ssh (they don't log in to a full shell, I'm not sure what the term is for that). It's like executing ssh tom@blah.com "pwd" and it doesn't get the full environment you'd get when logging into a shell. It gets a very restricted environment that you can't normally change. So you must change a setting for sshd to allow yourself to setup extra environment variables for these ssh'ed commands.
So open /etc/sshd_config and make sure the line:
PermitUserEnvironment yes
...exists and is uncommented. Now set up the custom environment for your user (the user you deploy as) by creating the file ~/.ssh/environment and adding:
PATH=/opt/local/bin:/opt/local/sbin:/opt/local/apache2/bin:/bin:/sbin:/usr/bin
That's it! Although I think you have to restart sshd by toggling Remote Login off and on in Sharing preferences or rebooting hte machine.
First you'll need gcc installed. So download the install the developer tools (now just called XCode) from apple and install.
You'll want to fix up Apple's ruby installation now. First download the latest rubygems:
cd ~
curl -O http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar -xvzf rubygems-0.8.11.tgz
cd rubygems-0.8.11
sudo ruby setup.rb
Now we have rubygems installed, we'll fix the OS X ruby configuration by installing the fixrbconfig gem:
sudo gem install fixrbconfig
sudo fixrbconfig
If you're using Tiger (I think it's okay under Panther) the last command will have resulted in an error:
/usr/lib/ruby/1.8/powerpc-darwin8.0/ruby.h does not exist.
This probably means you haven't yet installed Xcode from the
Tiger DVD. You won't be able to compile Ruby extensions without
it. Please install it then rerun this program.
The widely reported fix this error looks like this:
cd /usr/lib/ruby/1.8/
ln -s universal-darwin8.0/* powerpc-darwin8.0
Though I suspect there is a neater way to fix the problem, Oh well. Now we re-run:
sudo fixrbconfig
Now lets install the rails gem:
sudo gem install rails
Now install the mysql ruby bindings from source to avoid the various problems associated with installed it via gem:
cd ~
curl -O http://tmtm.org/downloads/mysql/ruby/mysql-ruby-2.7.tar.gz
tar xzvf mysql-ruby-2.7.tar.gz
cd mysql-ruby-2.7
ruby extconf.rb --with-mysql-config
make
sudo make install
Now we'll install fastcgi. Download the main fastcgi package:
cd ~
curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar -xvzf fcgi-2.4.0.tar.gz
Build it!
cd fcgi-2.4.0
./configure --prefix=/usr/local
make
sudo make install
Now install the ruby fcgi bindings:
sudo gem install fcgi
Don't worry about the "No definition for xxx" output - I don't think that matters (just rdoc warnings). Now we need to install the apache fastcgi module, mod_fastcgi:
cd ~
curl -O http://fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
tar xzvf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2
apxs -o mod_fastcgi.so -c *.c
sudo apxs -i -a -n fastcgi mod_fastcgi.so
This will add the necessary lines to http.conf to load mod_fastcgi. You will still need to configure the module. Open up /etc/httpd.conf and add:
<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
</IfModule>
... somewhere near the end of the file.
Assuming you want to run your rails application on a virtual server (which you have added via the Server Admin GUI app) you'll need to slightly edit the apache configuration for the virtual server so that settings can be overriden with the .htaccess file present in your rails app's public directory.
Find the configuration file for your virtual server in /etc/httpd/sites/, e.g. 0019any80_www.myserver.com.conf. Find the line 'AllowOverride None' and change it to 'AllowOverride All'.
Then deploy your rails application in whatever way you wish. I recommend using SwitchTower.