Phusion Passenger – Deploying Rails on Mac OS X Apache
I’ve been working on learning and developing Rails. One of the features I enjoyed while doing Grails was the ease in which it took to deploy and run my Grails app in Apache.
I’m sure there are other ways to do this, most were, quite honest way over my head – but I started to investigate options and ran into ‘Phusion Passenger’, a.k.a. mod_rails or mod_rack. From the website:
Phusion Passenger™ — a.k.a. mod_rails or mod_rack — makes deployment of Ruby web applications, such as those built on the revolutionary Ruby on Rails web framework, a breeze. It follows the usual Ruby on Rails conventions, such as “Don’t-Repeat-Yourself”.
- Deployment is only a matter of uploading application files. No Ruby (on Rails)-specific server configuration required!
- Supports both the industry standard Apache web server and the fast and lightweight Nginx web server.
- Allows Ruby on Rails applications to use about 33% less memory, when used in combination with Ruby Enterprise Edition (optional).
- Zero maintenance. No port management, server process monitoring or stale file cleanup required. Errors are automatically recovered whenever possible.
- Designed for performance, stability and security. Phusion Passenger should never crash Apache even in case of crashing Rails applications.
- Well-documented, for both system administrators and developers!
The installation (this is for Mac OS X Snow Leopard) – especially the video is very straightforward.
Let me repeat the steps I went through, because honestly, the Phusion Passenger install was a piece of cake, however, my Apache setup as a Mac OS X user was new to me and so I wanted to share these steps for anyone else like me who might struggle on this part. I am going to assume you have a Rails app and have made it that far.
First, you shouldn’t have to install Apache on Snow Leopard, it comes with the OS. You can check in your System Preferences.
(note, you can stop and start Apache by checking/unchecking Web Sharing)
The last important piece here to understand is ‘where’ Apache lives on your Snow Leopard install. I’m assuming it’s the same (at least for most of us) – located here:
Finally, I’m going to highly recommend TextWrangler if you are not a Vi user, TextWrangler is a great (& free!) texteditor for Mac – and it lets you access and alter files that require sudo access, etc…
Ok, let’s get started. I suggest you fire up the video link and follow along:
1. open up Terminal, enter the following to install passenger:
sudo gem install passenger
2. next, install the apache2 module:
At the end of the install, passenger provides some critical information, ie.
The text above might differ for your machine, but you need to copy that text to put in your Apache config.
3. Open up TextWrangler – goto File – Open File by Name (or use terminal for vi):
4. Goto the bottom of the file and paste in your contents. ie.
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
5. Now, assuming you have the built in Apache install for Snow Leopard – we need to setup virtual hosts
Goto this line in the httpd.conf and remove the # – it should look like below:
# Virtual hosts
Ok, you are done with httpd.conf – save it
6. Now we need to add our Virtual host information, open the conf file in TextWrangler:
Check for the following:
NameVirtualHost *:80 (just validate this is there)
Comment out the existing <VirtualHost *:80> entries
Add the following:
Then add your app – the example would be:
NOTE: above should be the path to your rails app – and the name you want to give the app for it’s URL. Additionally, it must point to the ‘public’ folder in your rails app!
7. Ok, we are almost there, now we need to tell our machine how to access the app, so we need to open our hosts file and edit it. Back to TextWrangler and open file by name: /private/etc/hosts
Add a line at the bottom like this example:
This entry should match the ServerName as set above (ie. book_shelf and book_shelf)
8. Go back to your Web Sharing, uncheck and check to restart Apache (or use the terminal cmd)