Intridea Development Blog
Deploying your Rails applications with Phusion Passenger
There have been several methods to deploy an Ruby on Rails application. Until recently, the most popular is to run Apache and proxy balance to multiple Mongrel instances that are running simultaneously.
Passenger, developed by Phusion, is the new kid entering the Rails deployment market. Everyone has been using the Apache PHP module for years and deploying a PHP applications is a snap. This has not been possible with Rails until Passenger. It is extremely easy, and you can still use Capistrano to automate deployment. I will show you how I get it to work on Ubuntu.
sudo gem install passenger
passenger-install-apache2-module
Update: Phusion just released Passenger 2.0 RC 1. You can download this version and do gem install passenger-1.9.0.gem instead. But I had an error compiling it on Mac OS X Leopard. hongli pointed me to use the version from GitHub that has the fix and it works like a charm. Thanks Phusion guys.
To get it from GitHub:
<code>git clone git://github.com/FooBarWidget/passenger.git
</pre>
I created a separate @/etc/apache2/mods-available/passenger.load@ and it contains the following:
For 1.0.5:
<pre><code>LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so
RailsSpawnServer /usr/local/lib/ruby/gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server
RailsRuby /usr/local/bin/ruby
</pre>
For the GitHub version (Of course the path will look different depending on where your git clone is):
<pre><code>LoadModule passenger_module /home/rlaw/downloads/passenger/ext/apache2/mod_passenger.so
PassengerRoot /home/rlaw/downloads/passenger
PassengerRuby /usr/local/bin/ruby
</pre>
I then tell Apache to load the Passenger module:
<pre><code>a2enmod passenger
</pre>
Now, I create a virtual host configuration for one of my Rails app in <code>/etc/apache2/sites-available/myapp</code>:
<pre><code><VirtualHost *:80>
ServerAdmin webmaster@myapp.com
ServerName myapp.com
DocumentRoot /home/deploy/apps/myapp/current/public
<Directory /home/deploy/apps/myapp/current/public>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
LogLevel warn
ErrorLog /var/log/apache2/myapp/error.log
CustomLog /var/log/apache2/myapp/access.log combined
</VirtualHost>
</pre>
I then restart Apache:
<pre><code>sudo /etc/init.d/apache2 reload
</pre>
When you need to restart your application because you have changed some code that Rails does not reload in production, just do:
<pre><code>touch /home/deploy/apps/myapp/current/tmp/restart.txt
</pre>
I have not tried their "Ruby Enterprise Edition":http://www.rubyenterpriseedition.com/ yet. They claim substantial memory and speed improvement at "RailsConf 2008":http://en.oreilly.com/rails2008/public/schedule/detail/4354, so it will be interesting to see how that develops.
The Intridea Blogs
Blog Archive
- June 2009 (2)
- May 2009 (1)
- April 2009 (3)
- March 2009 (8)
- February 2009 (9)
- January 2009 (2)
- December 2008 (1)
- November 2008 (1)
- October 2008 (2)
- July 2008 (5)
- June 2008 (8)
- April 2008 (3)
- March 2008 (1)
- February 2008 (4)
- January 2008 (4)
- December 2007 (3)
- November 2007 (3)
- October 2007 (4)
- September 2007 (2)
- August 2007 (3)
Raymond Law