Mac Yosemite, Rails, Phusion Passenger and Apache

added on :: 4 December 2014

If you ask me, whats your preffred Ruby on Rails server, without thinking twice I'd say "Phusion Passenger".  Why you may ask, Weeeel to start with It works, it is fast, it gives quality error messages and it has not let me down. I use "Phusion Passenger" for development as well. Why not, if you are going to use that in production my humble advice is what ever you are going to have in production have it in development. That would lead to less headaches down the road.

Install "Phusion Passenger" on a Mac.

If you read the how to at there are multiple ways to install. I highly recommend go with the homebrew method.  Reason is if you install the gem, every time you change your Ruby version you may need to install the gem all over again.

brew install passenger

That would install passenger system wide without having to know anything about independent of the Ruby version or whether the Passenger gem is installed.

After you install passenger with homebrew, read the lines of installation. It would say something along the lines of

 To activate Phusion Passenger for Apache, create /etc/apache2/other/passenger.conf:

Do as the Romans and create that. and it says  you add lines similar to bellow to passenger.conf file

  LoadModule passenger_module /usr/local/opt/passenger/libexec/buildout/apache2/
  PassengerRoot /usr/local/opt/passenger/libexec/lib/phusion_passenger/locations.ini
  PassengerDefaultRuby /usr/bin/ruby

Now the part that you have to keep an eye is the last line. That line says give the path to the system Ruby. I don't use the default system Ruby eh!. I use a Ruby version manager.  In my case it is Rbenv ( and Rbenv works like a charm. So you have to get your current running Ruby path

To get that

which ruby

and you would see "/Users/myokcompter/.rbenv/shims/ruby"

So you need to add that the /etc/apache2/other/passenger.conf file and comment out the #PassengerDefaultRuby /usr/bin/ruby

  LoadModule passenger_module /usr/local/opt/passenger/libexec/buildout/apache2/
  PassengerRoot /usr/local/opt/passenger/libexec/lib/phusion_passenger/locations.ini
  #PassengerDefaultRuby /usr/bin/ruby
PassengerDefaultRuby /Users/anthony/.rbenv/shims/ruby

If you don't do that, you would get all sorts of errors like bellow, as most of your apps gems may not be installed in the system-wide ruby version.

Web application could not be started

cannot load such file -- bundler/setup (LoadError)
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/Cellar/passenger/4.0.53/libexec/lib/phusion_passenger/loader_shared_helpers.rb:263:in `block in run_load_path_setup_code'
/usr/local/Cellar/passenger/4.0.53/libexec/lib/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler'
/usr/local/Cellar/passenger/4.0.53/libexec/lib/phusion_passenger/loader_shared_helpers.rb:261:in `run_load_path_setup_code'
/usr/local/Cellar/passenger/4.0.53/libexec/helper-scripts/rack-preloader.rb:100:in `preload_app'
/usr/local/Cellar/passenger/4.0.53/libexec/helper-scripts/rack-preloader.rb:158:in `'
/usr/local/Cellar/passenger/4.0.53/libexec/helper-scripts/rack-preloader.rb:29:in `'
/usr/local/Cellar/passenger/4.0.53/libexec/helper-scripts/rack-preloader.rb:28:in `

So now that passenger is ready and talking to Ruby. Good start.

Now is the time to add a Ruby on Rails application

So it is time to be super user
sudo su

Go to

cd /etc/apache2

and create a directory called users if it is not available

cd users 

if you do a  "pwd" command you should see


So create the Apache configuration file for all your Rails applications.

nano myokcompter.conf

<VirtualHost *:80>
 DocumentRoot /Users/myokcompter/railsapps/ifree/public
  RailsEnv development
  # Other directives here
  <Directory &quot;/Users/myokcompter/railsapps/ifree/public&quot; >
     Options FollowSymLinks Indexes MultiViews
     AllowOverride none
     Require all granted

Add Apache VirtualHost files like above to all your Rails apps.

Now I like to call my locally served apps like "" where .app is the extension. Dont use .com or any other publicly available domain extensions.

Now this is a key part. You need to make sure that "/etc/apache2/users/myokcompter.conf" file gets loaded with Apache and it is in Apaches loading path. To do that you need to edit the "httpd.conf" file

So you can nano it
nano /etc/apache2/httpd.conf

and go all the way to the end of that file add the bellow line. That would load all files under users directory. If you wan to add a single file then (Include /etc/apache2/users/myokcompter.conf)

Include /etc/apache2/users/*.conf

OK nearly there.

Now you need to update "hosts" file. Why that is where the Apache go to before it go the World Wide Web. Now edit the "hosts" file

nano /etc/hosts

Update the hosts file with each of your web app name. Now the app name has to match the VirtualHost application name being the local IP for localhost.

I think you should be good to go

White you are in sudo mode you need to restart Apache. Here are the Mac commands

apachectl start
apachectl stop
apachectl restart

Hope this helps