This is what I had to do to get Passenger (aka mod_rails) up and running on my Mac. My computer is running OS X 10.5 with a default Ruby and Rails install. The websites I referenced for all the steps are listed at the end.
Prerequisites:
You will need to have XCode installed as mod_passenger.so needs to be compiled.
Installing Passenger Gem
The first thing is to install and build the Passenger gem.
$ sudo gem install passenger
$ sudo passenger-install-apache2-module
The second line will compile mod_passenger.so and launch an installer script. At the end of the script there will be 3 lines that you need to add to your Apache configuration in order for anything to work. Copy these lines directly from the install script as they may be unique to your computer.
Configuring Apache httpd.conf
In this section, we need to configure Apache so it can properly use mod_rails and access your Virtual hosts, which we will setup later. The lines you copied in the previous step need to be added to one of two files – /etc/apache2/httpd-conf or your personal configuration file, in my case /etc/apache2/users/chrisjohnston.conf. it doesn’t matter which one you pick. In getting this all running, I used both files and things worked fine. In the end, I picked my personal config file because it kept things cleaner.
To open the file, use the following:
$ sudo vim /etc/apache2/users/chrisjohnston.conf
This is what my file looks like. I will explain the various parts after the snippet.
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so
RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server
RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
RailsEnv development
<Directory "/Users/chrisjohnston/Sites/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "/Users/chrisjohnston/Dev/">
Order allow,deny
Allow from all
</Directory>
The first three lines load mod_passenger.so and set it up. The RailsEnv development line is needed in order to run the server in development mode. If this is to be a production server, then you can leave this line out as it defaults to production.
The next important part of the file is
<Directory "/Users/chrisjohnston/Dev/">
Order allow,deny
Allow from all
</Directory>
This gives you access to all the files below the given directory. This is important if you want things like stylesheets or images to load. We will also come back to this when we set up virtual hosts for the site.
Setting up Virtual Hosts
The next thing to do is to set up a virtual host for your website. In order for this to work, first open the apache httpd.conf file
$ sudo vim /etc/apache2/httpd.conf
and ensure the following line is uncommented, otherwise, nothing else beyond this point will work.
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
Once you have uncommented line, open up the httpd-vhosts.conf file and add a virtual host pointing to where you rails app is. Also, ensure that NameVirtualHost *:80 is uncommented.
$ vim /private/etc/apache2/extra/httpd-vhosts.conf
Here is what mine looks like:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
# Rails apps
<VirtualHost *:80>
DocumentRoot "/Users/chrisjohnston/Dev/studio_gallery/public"
ServerName dev.studiogallery.com
ErrorLog "/Users/chrisjohnston/Dev/studio_gallery/log/error.log"
</VirtualHost>
There may be two dummy virtual hosts listed in the file. Either comment these out or delete them. They will cause errors when you restart the server.
In the snippet above, you can see that I have set up a ServerName for my site. In order to navigate to this (without ending up searching for it on the net) we need to modify the /etc/hosts file. You need to add a line that tells your computer to associate the domain you created with your computer.
# Virtual hosts on this computer
127.0.0.1 dev.studiogallery.com
Now we can restart Apache.
$ sudo apachectl restart
And if everything goes well, when you navigate to your virtual site, your Rails app should come up.
From the highgroove Studio’s The Napkin website, I also added the following to my .bash_profile file:
# Use this in any RAILS_ROOT dir. That restart.txt file tells mod_rails to restart this app.
# You'll want to do this when (for example) you install a new plugin.
alias restart_rails='touch tmp/restart.txt'
# By default, your app's error log now goes here. Unless you configure your apps otherwise,
# it's helpful to have an alias to take you to your error log quickly.
alias apache_logs='cd /private/var/log/apache2/'
# You'll be adding to your vhosts configuration everytime you introduce a new Rails app.
# Might as well make it a shortcut
alias vhosts='sudo vi /private/etc/apache2/extra/httpd-vhosts.conf'
# Dito with hosts
alias hosts='sudo vi /etc/hosts'
# You'll need to restart apache whenever you make a change to vhosts.
# You can also click System Preference->Sharing->Web Sharing, but this is quicker.
alias apache_restart='sudo apachectl restart'
References: