Using Passenger on OS X for Rails development

Manfred Stienstra, 16 Apr 2008, 15:08 in ruby on rails, last updated 28 Jul 2008, 09:52 (edit).

Lately a few things have been bugging me about Rails development using script/server. First, I can’t test through SSL and for applications who switch between SSL and non-SSL you really want your development environment too look as much like production as possible. And secondly, I have to manually manage my app server with script/server. This is a bit of a pain because some of our applications use ActiveResource to communicate so I need to start several app processes.

Proxying trough Apache solved the SSL problem, but now I had to remember on which ports I had to start my app server.

The solution turned out to be Passenger. First we install the passenger gem and compile mod_passenger.so.

$ gem install passenger
$ passenger-install-apache2-module

After that we turn on Apache at System PreferencesSharingWeb Sharing and edit the webserver configuration. I added everything to /etc/apache2/users/manfred.conf but Apache doesn’t really care where you put it, just remember to load mod_passenger.so before using Passenger specific configuration options.

Set up the Passenger configuration as explained at the end of the install script.

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so
RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server
RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

Make sure our apps run in development mode.

RailsEnv development

Allow Apache serve files from our development directories.

<Directory "/Users/manfred/Code">
    Order allow,deny
    Allow from all
</Directory>

Finally, configure virtual hosts for our various projects.

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot "/Users/manfred/Code/project1/public"
ServerName project1.local
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Users/manfred/Code/project2/public"
ServerName project2.local
</VirtualHost>

Update: Adam Meehan has a short writup on how to connect ruby-debug to a Rails instance running in Passenger.

Comments

  1. Simeon 1 day later: (delete)

    Are you using leopard? I did this the other day, but I only get seg faults using the built in apache. I was really hoping this would be the silver bullet, but its giving my nothing but trouble :(

  2. Manfred Stienstra 1 day later: (delete)

    Yeah, it's fine on a number of Leopard installs in our office, on my personal laptop I'm having segfaults too. Do you happen to have a case sensitive filesystem?

  3. Simeon 1 day later: (delete)

    Nope, just the stock mac fs. Its odd how it picks and chooses :)

    I dont feel like installing mac ports, which is what the folks I have seen using it have done.

  4. Tim Dysinger 1 day later: (delete | show email)

    I installed it on my macbook, but I didn't use the Apple-installed Apache because of all the warning's saying don't do that in the installer.

    Here's how I did it. http://dysinger.net/2008/04/14/installing-apache-and-mod_rails-on-mac-os-x-leopard/

  5. Manfred Stienstra 1 day later: (delete)

    Yeah, installing Apache would be a solution, but I would prefer it if it would work with OSX out of the box. It would be a shame to loose the simplicity of Passenger on OSX.

  6. Manfred Stienstra 15 days later: (delete)

    Since 1.0.2 everything runs fine on OSX.

  7. topfunky 21 days later: (delete | show email)

    I also had to edit /etc/hosts to add the app1.local and corresponding domains.

    An added benefit is that pages that reference multiple dynamically generated resources will load much faster. I have reporting pages that generate 20+ graphics, and it was nearly unusable with a single Mongrel. Passenger spawns extra processes and works much faster, even in development.

  8. marcus 34 days later: (delete)

    haha that was great. i was hesitant to switch on my dev box because i thought it'd be a pain (even though my experience w/ mod_rails elsewhere indicated otherwise). it took me 10 minutes and it works perfectly so far.

    thanks for the writeup!

  9. Erwin 37 days later: (delete | show email)

    great... running under 10.5.2..
    only problem not yet solved, all images, javascript files, css files cannot be loaded , still with 0.0.0.0:3000
    http://0.0.0.0:3000/images/pdmlogo.gif?1211129216
    ..
    how can I fix it ? I tried to set RAILS_ROOT to mydomain.local, but then it failed...

    thanks

  10. Erwin 37 days later: (delete | show email)

    sorry .. got it.. solves this issue ... (I needed to think like an Apache... !)

    config.action_controller.asset_host = "http://mydomain.local";

    inserted in config/environments/development.rb

  11. Cameron 37 days later: (delete)

    This installs perfectly on OS 10.5.2 with Passenger 1.0.5. Many thanks, I'm replacing mongrels asap...

  12. Manfred Stienstra 38 days later: (delete)

    @Erwin, RAILS_ROOT is the root directory of the Rails project (ie. /Users/manfred/Code/my_rails_project) and has nothing to do with the domain.

    Fixing the asset_host is indeed the right way to solve it.

  13. nick 40 days later: (delete | show email)

    Is there any way to still use the debugger in this case? i.e. script/server -u

  14. Manfred Stienstra 40 days later: (delete)

    @nick, no I don't think you can access the debugger.

  15. Brandon Martinez 61 days later: (delete | show email)

    @nick: what are you using the debugger for? You could just use this if you are trying to debug your rails apps:

    tail -f rails_app/log/development.log

    That will give you live output from your rails app.

  16. Jamie Orchard-Hays 65 days later: (delete | show email)

    Manfred, thanks for the helpful write-up. I have done this setup on my Mac (Leopard) and find that the first virtual host always wins--pointing at the second one always goes to the first. I'm wondering if anyone else has had this problem. My /etc/hosts file looks like:

    127.0.0.1 localhost app.local app.admin

    but it doesn't matter what I change the names to.

    Thanks,
    Jamie

  17. Jamie+Orchard-Hays 65 days later: (delete | show email)

    Actually, the whole hosts file looks like:

    127.0.0.1 localhost app.local app.admin
    255.255.255.255 broadcasthost
    ::1 localhost
    fe80::1%lo0 localhost

  18. Manfred Stienstra 67 days later: (delete)

    Jamie, I don't really understand what you're talking about.

  19. Jamie+Orchard-Hays 68 days later: (delete | show email)

    Manfred, never mind. I was missing

    NameVirtualHost *:80

  20. Sam 76 days later: (delete | show email)

    Thanks for the write-up. I got everything running fine in under 5 minutes!

  21. Andrew Vit 80 days later: (delete)

    Any way to specify a different environment than the predetermined "development" or "production"?

  22. Andrew Vit 80 days later: (delete)

    Oops, that last comment was meant for the Passenger prefPane post...

  23. Manfred Stienstra 80 days later: (delete)

    No, just development and production.

  24. pedz 102 days later: (delete | show email)

    I'm not getting this to work for me. In the examples you have, what is the URL used to access a site? I assume it is:

    http://project1.local/what/ever/...

    I can't get that name to map to 127.0.0.1. I tried Top Funky's idea of adding it to /etc/hosts but then when I do:

    host project1.local

    I get:

    Host project1.local.my.domain.com not found: 3(NXDOMAIN)

    I'm running 10.5.4

  25. Manfred Stienstra 102 days later: (delete)

    Yes, you should be able to access the project through http://project1.local once you've added it to /etc/hosts or your DNS server. I'm afraid you don't really provide enough information for me to guess what's wrong though.

    Note that 'host' doesn't know about /etc/hosts nor the OS X Directory Services. Sometimes a 'dscacheutil -flushcache' and a Safari restart helps when you have trouble resolving stuff.

  26. flax (salomon.valverde@gmail.com) 120 days later: (delete)

    how do you get passenger to run your rails app in development mode?

  27. Manfred Stienstra 120 days later: (delete)

    Using RailsEnv: http://www.modrails.com/documentation/Users%20guide.html#rails_env

  28. flax 120 days later: (delete)

    hah!

    RTFM right?

    thanks much

  29. der_flo 138 days later: (delete)

    A quick question:
    Where goes the STDOUT and STDERR? I usually use "puts" in development and a cannot redirect these logs via the "ErrorLog" Apache directive. Any ideas?

  30. Manfred Stienstra 138 days later: (delete)

    It's probably a good idea to use logger.debug instead and look at RAILS_ROOT/log/development.log.

Add your comment

In order to fight spam on this blog, posting comments from a browser without javascript is currently not supported.