How to set up Apache with Passenger (mod_rails) on Mac OS X

apache-2.2mac-osxphusion-passengerruby-on-rails

I'm an iOS developer, so I have very little experience with Apache and RoR, and it's the first time I'm trying to use Mac OS X as server.

http://rubyonrails.org/deploy recommends using Phusion Passenger (mod_rails) with Apache. So that's what I'm trying to accomplish, but I've hit a dead end.

This is what I've done:

  1. I've enabled Apache (check box in settings) and pointing my browser to localhost gives me the text "It works!". I can also access it through my dyndns.

  2. I ran the following commands to install passenger:

    sudo gem install passenger
    passenger-install-apache2-module
    
  3. I added the following lines to /etc/apache2/httpd.conf:

    LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
    PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-3.0.7
    PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    
  4. Then I added the following to /etc/apache2/extra/httpd-vhosts.conf:

    <VirtualHost *:80>
       ServerName my.dyndns.org
       DocumentRoot /Users/Shared/rails/project/public    # <-- be sure to point to 'public'!
       <Directory /Users/Shared/rails/project/public>
          AllowOverride all              # <-- relax Apache security settings
          Options -MultiViews            # <-- MultiViews must be turned off
       </Directory>
    </VirtualHost>
    
  5. I restarted Apache using:

    sudo /usr/sbin/apachectl restart
    

I have a working rails application at /Users/Shared/rails/project, i.e., running rails server works. It's just the "Welcome aboard, You’re riding Ruby on Rails!" page, but it works.

The problem is that I haven't figured out how to access that page through Apache and Passenger. I don't know how to configure a virtual host and I barely know what it is. Can anyone explain to me what I'm doing wrong and how to fix it?

EDIT: Just to be clear. I want my.dyndns.com/project to be publicly available on the Internet. What I'm getting now is "The requested URL /project was not found on this server."

EDIT 2: It seems like there aren't any virtual hosts:

$ sudo /usr/sbin/apachectl -S
VirtualHost configuration:
Syntax OK

Is there anything else that needs to be done besides adding the virtual host in /etc/apache2/extra/httpd-vhosts.conf?

Best Answer

I was recently awarded the popular question badge for this question, so I thought it was about time I posted the answer. I'll just post the relevant parts of my conf files.

So in /etc/apache2/httpd.conf I have the following:

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-3.0.7
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

Also make sure to uncomment the following line:

Include /etc/apache2/extra/httpd-vhosts.conf

Then in /etc/apache2/extra/httpd-vhosts.conf I have the following:

NameVirtualHost *:80

<VirtualHost *:80>
   ServerName example.dyndns.org
   DocumentRoot "/Users/Shared/rails/project/public"
   <Directory /Users/Shared/rails/project/public>
      AllowOverride all
      Options -MultiViews
      Order allow,deny
      Allow from all
   </Directory>
</VirtualHost>

After today I will not have access to this server. We don't use it anymore. Instead we use Heroku. So if it's not working for you, for some reason, or I've forgot some vital part of the configuration, I will not be able to help you. It may be outdated and I don't know if it works with newer versions of passenger. Also the server was using Mac OS X Snow Leopard, so it may not work with other versions of OS X. However, my guess is that it hasn't changed all that much and that most of this is still valid.

I also want another disclaimer. This may not be the safest configuration. I don't understand all the options, but it seems to be very allowing. I had a colleague help me with the configuration and this is simply the first version of the configuration that we got working. We did not care much about the security since it was only a dev server and not production.

If you have any suggestions on how to improve the configuration, please feel free to post those. Even though I will not have any use for those, others still might. After all, this is a popular question.