Tim Dysinger RSS

Apr
14th
Mon
permalink

Installing Apache and mod_rails on Mac OS X Leopard

Phusion Passenger ( mod_rails ) is out so I thought I would give it a twirl. The mod_rails site has some install notes but it doesn't go far enough. However, once you do the install and get used to it, it is a rather friendly setup. I can see it being a big boost to rails shared-hosting. The rails instances are scaled up and down on the fly behind apache so no static pre-configured pools of mongrel with monit watching them needed. Here's how I got it going on the mac: Update 6/16: Moved instructions to MacPorts instead of raw install

# Install macports + macports ruby + macports rubygems
sudo port install apache2 +preforkmpm
export APACHE=/opt/local/apache2
export PATH=$APACHE/bin:$PATH
sudo gem install rails passenger
export VERS=`passenger-config --version`
sudo passenger-install-apache2-module
sudo cp $APACHE/conf/httpd.conf.sample $APACHE/conf/httpd.conf
sudo chgrp -R admin $APACHE/conf
sudo chmod -R g+w $APACHE/conf
sudo chmod 2775 $APACHE/conf $APACHE/conf/extra
echo "Include conf/extra/httpd-rails.conf" >> $APACHE/conf/httpd.conf
cat >$APACHE/conf/extra/httpd-rails.conf <<EOF
LoadModule passenger_module /opt/local/lib/ruby/gems/1.8/gems/passenger-$VERS/ext/apache2/mod_passenger.so
RailsSpawnServer /opt/local/lib/ruby/gems/1.8/gems/passenger-$VERS/bin/passenger-spawn-server
RailsRuby /opt/local/bin/ruby
NameVirtualHost *
<VirtualHost *>
ServerName myapp.com
ServerAlias *.myapp.com
RailsEnv development
# For each webapp
DocumentRoot /Users/me/Projects/myapp/public
<Directory /Users/me/Projects/myapp/public>
Allow from all
</Directory>
</VirtualHost>
EOF
sudo $APACHE/apachectl start
exit
That's it. You can see that you can add more <VirtualHost *> entries for other applications. You need to put www.myapp.com hostname on the end of the "localhost" line in /etc/hosts.