Chris Johnston

Web development and design with a little VFX thrown in for fun
  • Home
  • About Me
  • Contact Me
  • Projects
  • Resume

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

Published by Chris Johnston on May 29, 2008 01:15 am under Ruby on Rails

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:

  • highgroove Studio, The Napking – Development with Rails + Passenger (AKA mod_rails) on Mac
  • Fingertips website – Using Passenger on OSX for Rails development

10 Comments so far

  1. Min Soo Kim on May 29th, 2008

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

  2. Thomas on May 30th, 2008

    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. Chris Johnston on May 31st, 2008

    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 on May 31st, 2008

    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. Chris Johnston on June 1st, 2008

    @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 on June 11th, 2008

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

  7. topfunky on June 16th, 2008

    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. timfitz on August 14th, 2008

    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. Christoph on September 5th, 2008

    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 on September 5th, 2008

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

Posting your comment.

  • Search

  • Categories

    • .NET (2)
    • Agile (41)
    • Apple Mac (15)
    • Application Development (124)
    • Articles (4)
    • ColdFusion (2)
    • Demo/Tutorial (3)
    • Eclipse (1)
    • Flash (6)
    • General (567)
    • Git (1)
    • Google (1)
    • Hibernate (4)
    • J2EE (39)
    • Java (111)
    • Java Frameworks (5)
    • Links (1)
    • Linux (33)
    • Miscellanous (2)
    • NetBeans (3)
    • News (10)
    • Open Source (6)
    • Photography (2)
    • Programming (33)
    • Python (1)
    • Ruby (27)
    • Ruby on Rails (14)
    • Ruby on Rails Web Apps (1)
    • Software (14)
    • Spring (4)
    • Teaching (1)
    • TeamDocs (6)
    • Technology (2)
    • Test Driven Development (1)
    • Thoughts (33)
    • ThoughtWorks (8)
    • Tips and Tricks (1)
    • User Experience (1)
    • Web Design (7)
    • Web Development (37)
    • Wicket (1)
  • Archives

    • September 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (7)
    • March 2009 (2)
    • February 2009 (6)
    • January 2009 (4)
    • December 2008 (3)
    • October 2008 (1)
    • September 2008 (2)
    • August 2008 (6)
    • July 2008 (4)
    • June 2008 (1)
    • May 2008 (8)
    • April 2008 (7)
    • March 2008 (2)
    • February 2008 (1)
    • January 2008 (5)
    • December 2007 (3)
    • November 2007 (4)
    • October 2007 (5)
    • September 2007 (2)
    • August 2007 (3)
    • July 2007 (6)
    • June 2007 (5)
    • May 2007 (5)
    • April 2007 (5)
    • March 2007 (6)
    • February 2007 (9)
    • January 2007 (16)
    • December 2006 (6)
    • November 2006 (15)
    • October 2006 (17)
    • September 2006 (27)
    • August 2006 (22)
    • July 2006 (14)
    • June 2006 (10)
    • May 2006 (18)
    • April 2006 (3)
    • March 2006 (6)
    • February 2006 (15)
    • January 2006 (7)
    • December 2005 (11)
    • November 2005 (8)
    • October 2005 (18)
    • September 2005 (24)
    • August 2005 (18)
    • July 2005 (21)
    • June 2005 (14)
    • May 2005 (23)
    • April 2005 (18)
    • March 2005 (34)
    • February 2005 (27)
    • January 2005 (27)
    • December 2004 (15)
    • November 2004 (17)
    • October 2004 (20)
    • September 2004 (10)
    • August 2004 (21)
    • July 2004 (9)
    • June 2004 (11)
    • May 2004 (4)
    • April 2004 (15)
    • March 2004 (12)
    • February 2004 (7)
    • January 2004 (17)
    • December 2003 (11)
    • November 2003 (8)
    • October 2003 (12)
    • September 2003 (12)
    • August 2003 (12)
    • July 2003 (23)
    • June 2003 (22)
    • May 2003 (14)
    • April 2003 (9)
    • March 2003 (22)
    • February 2003 (24)
    • January 2003 (32)
    • December 2002 (11)
    • November 2002 (16)
    • October 2002 (10)
    • September 2002 (9)
    • August 2002 (13)
  • Pages

    • About Me
    • Contact Me
    • Projects
    • Resume

Copyright © 2010 Chris Johnston
WordPress Theme based on Light Theme