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

12,677

Solution 1

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.

Solution 2

https://github.com/Fingertips/passengerpane

I would try downloading the Passenger Preference Pane and using that to set up your development environment. Otherwise, if you are really adventurous, try out http://pow.cx. I use Pow myself for my Rails development.

If you do go with Pow, I recommend the powder gem along with it for managing your Pow installation. It should be as simple as:

gem install powder

That should be all you need to do and then read up on powder here: https://github.com/Rodreegez/powder

Share:
12,677
Erik B
Author by

Erik B

Professional iPhone and iPad developer. I have some of Sweden's most downloaded apps on my resume. #SOreadytohelp

Updated on September 18, 2022

Comments

  • Erik B
    Erik B over 1 year

    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?

    • Erik B
      Erik B over 11 years
      I posted the configuration that worked for me. It's the accepted answer. I don't know if it's outdated by now, but hopefully it will help someone.
  • Erik B
    Erik B almost 13 years
    This will only work locally, right? I mean if I try to access project.dev on another computer it will not work. I want my.dyndns.org/project to be publicly accessible.
  • Bob Martens
    Bob Martens almost 13 years
    Pow is only for your machine. To publicly share you will need to point a domain name to your machine (probably through dyndns I am expecting) and then also update the ServerName in your config to represent that change (changing it to your domain name).
  • Erik B
    Erik B almost 13 years
    It seems like that's what I've done. With the above configuration shouldn't my.dyndns.com run my rails app and not show Apache's "It works!"?
  • Bob Martens
    Bob Martens almost 13 years
    It will if you have Apache set up to point to the folder and Passenger set up properly to have Rails requests sent to Passenger.
  • Erik B
    Erik B almost 13 years
    I got it working and I probably should post the solution, but I'm having trouble finding the time.