Home > Ruby on Rails > Installing Phusion’s Passenger on Leopard (OS X 10.5)

Installing Phusion’s Passenger on Leopard (OS X 10.5)

May 29th, 2008

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:

Categories: Ruby on Rails Tags:
  1. Min Soo Kim
    May 29th, 2008 at 18:04 | #1

    Hi,
    Thank you for your instructions.
    Keep up the good work.

  2. Thomas
    May 30th, 2008 at 06:21 | #2

    Hi, great write-up !

    But any idea why I keep getting “Forbidden to access /” from Apache on 10.5.3 ? What may I have overlooked ?

    Only difference to your recipe is that I use “.local” domains …

  3. May 31st, 2008 at 00:09 | #3

    I had this same error and it was because I forgot to allow access to the directories where the virtual host was pointing. Did you remember to put something similar to this in to your httpd.conf file?

    <Directory "/Users/chrisjohnston/Dev/">
        Order allow,deny
        Allow from all
    </Directory>
    

    The Directory in the first line should point to a parent directory of where your rails app is located and where your virtual host points to. In my case, I simply grant access to my entire Dev directory so I don’t have to worry about it for future apps I may want to deploy.

    Other than that, I am not sure. I have not used .local domains before on a Mac. Good luck in figuring it out.

  4. Thomas
    May 31st, 2008 at 16:33 | #4

    Hi again,

    You mean in “[...]/apache2/users/myshortname.conf” ? Yes I have a similar Directory block there as per your recipe. I guess you don´t need it in httpd.conf as well.

    But you mention another interesting thing: “..allow access to the directories..”. Can you check which users on your system that has access to your “Dev” directory ? I know apache2 works as user “www” and on my system “www” does not specifically have access to the directory I want to host from… Is this a problem ? How to specifically give access ?

  5. June 1st, 2008 at 00:18 | #5

    @Thomas – unfortunately, you have moved beyond my knowledge of Apache running on OS X. I have only set up the one virtual host on my machine so far and it is only for development. It is not being served publicly. I am also not sure how to check which users have access to a particular directory in OS X. My *nix skills are a little rusty.

  6. Thomas
    June 11th, 2008 at 06:37 | #6

    Damn, can´t get this working still .. Still forbidden..

  7. June 16th, 2008 at 12:12 | #7

    I ended up storing my configurations in a SCM in my home directory so I can easily sync them from my desktop to my laptop. You may need to tweak permissions to get this to work correctly.

  8. August 14th, 2008 at 16:38 | #8

    Thank you very much for this info. I’m now to OS X and I’ve been trying to get my virtual hosts setup for awhile. I wish I would have found this post earlier.

  9. September 5th, 2008 at 07:18 | #9

    Hi,

    i have the same problem. Always getting the following error:

    “You don’t have permission to access / on this server.”

    I configured my DocumentRoot in the vhost file to: /Users/christophbunte/Documents/workspace/project1/public

    I tried to set the directory rules for the very same directory to “allow from all”. But that doesn’t help at all. Do i have to set file system permissions for the apache user?

    Any help or suggestions are highly appreciated

  10. Thomas
    September 5th, 2008 at 17:06 | #10

    I ended up giving user www access to the folders in file sharing.

Comments are closed.