While working with PHP, I realized that deployment of a PHP application is far more easier as compared to deployment of a Ruby on Rails application. So I was wondering if there could be a way to deploy a Ruby on Rails application in a similar fashion, as easy as you check out the Rails project in a directory on the server, configure a VirtualHost in the webserver, restart the webserver and there you go, everything should work as expected.
deploy rails website with passenger -rails deployment with passenger
Luckily I did find a saviour,
“Phusion Passenger” a.k.a “mod_rails” or “mod_rack”
Here I am putting down steps to ride Rails on Passenger.
Passenger is available as a Rubygem. As root,
gem install passenger
Install Passenger module for Apache
During installation it will prompt:
The Apache2 module was successfully installed.
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so
NOTE: Do NOT copy-paste from here. Make sure you add the lines that passenger prompts you with.
It is specific to the OS installation. Mine was a Fedora Core 10 64-bit installation.
Next, it will help you to configure a VirtualHost for Apache
/sbin/service httpd restart
That’s it, we are done.
Point your browser to your domain, and you should be able to see your Ruby on Rails Application.
Do keep in mind that the default Rails environment while using Passenger is “production”
To access your application in “development” or any other environment add the following line in your VirtualHost configuration:
Restarting your application deployed in production environment:
To restart your Rails application deployed in production environment you can restart Apache.
But that’s not a good solution if you are hosting multiple applications on the same server, or even generally, it doesn’t sound like a good idea to restart Apache every now and then.
To overcome that, you can restart your application in the following way:
From Rails Root Directory,
That’s it, this will restart you Rails application.
The best part is, Passenger is compatible with all the Rubygems and Rails plugins.
So nothing should break. I personally tried running a complex Rails application that uses Solr as the search engine along with acts_as_solr plugin, backgroundRB server for background processes, attachment_fu for file uploads etc, etc.
Everything worked like a charm.
For further configuration, please refer to the Passenger documentation found here:
You can also use Passenger to serve Non-Rails Ruby web applications. That can be a good alternative to the already prevalent mod_ruby module for Apache.
If you are using Nginx as your webserver, you can use Passenger module for Nginx.
There’s just one disadvantage to Passenger:
It doesn’t work on Windows. In any case, I personally never prefer to develop Rails (or any other) applications on Windows 🙂
Good news for Mac users:
fingertips has come up with an OS X preference pane for Phusion Passenger (a.k.a. mod_rails) that makes it a cinch to deploy Rails applications using Passenger on the Mac. It can be as simple as dragging a Rails application folder onto the preference pane! This is absolutely ideal for quick and easy Rails development on OS X.
You can download the Passenger Preference Pane here