Introducing Passenger (aka mod_rails)
I know what you’re thinking… isn’t this for Ruby on Rails, rack and similar frameworks? Why yes it is. As it says on their site:
Easy and robust deployment of Ruby on Rails applications on Apache and Nginx Webservers.
However there’s a less known “proof-of-concept” feature built into Passenger… it can load Python (WSGI) applications, and very easily at that.
Since this is built for Ruby, the easiest way to get it is to get Ruby installed, so lets get started on that (who knows maybe you’ll give ruby a try since it’ll be just as easy to deploy).
Installing Ruby
For this walk thru the test system is a minimal install Debian 5.3 system as root which comes natively with Python 2.5. If you’re reading this you probably already have Python installed and configured the way you want and simply want to utilize it thru Nginx.
Let’s first install the essentials to ensure there are no issues building Ruby from the source. (OpenSSL is required by Passenger, so install it even if you don’t think you need it. )
sudo apt-get install build-essential zlib1g zlib1g-dev zlibc libssl-dev libopenssl-ruby libopenssl-ruby1.9
Let’s make a src folder in your home directory, shown as ~/ on most systems, for example if you’re logged in as root, this will be /root/src/
cd ~/ mkdir src cd src
We’ll need to download and compile Ruby version 1.9.1 patch level 129. While this is not the latest, I’ve had unconfirmed reports that anything newer than p129 is not fully compatible with Passenger.
Confirmation from Hongli Lai, Co-founder of Phusion
This is correct. Later versions of 1.9.1 have bugs in the tempfile library. These bugs have been fixed in Rubys SVN repository but so far there hasnt been a 1.9.1 release containing the bug fixes.
You can either leave –prefix=/opt/ruby, or remove it, by leaving it you give yourself the easy ability of removing ruby and reinstalling as needed by simply typing rm -rf /opt/ruby.
wget ftp://ftp.ruby-lang.org:21//pub/ruby/1.9/ruby-1.9.1-p129.tar.gz tar zxvf ./ruby-1.9.1-p129.tar.gz cd ruby-.1.9.1-p129 ./configure --prefix=/opt/ruby make sudo make install
Once installed we need to check to verify that it is indeed installed, the first line below is mainly if you choose to install to an alternate path (you may have to edit your ~/.bash_profile to make this permanent)
export PATH="/opt/ruby/bin:$PATH" ruby -v
If all went well you should see something like:
ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux]
We’re not quite done yet, we still got RubyGems and Rails to go before we can get Passenger installed.
Installing RubyGems
RubyGems will be the main component that makes installing Passenger easy. You could install Passenger from the source, but many components of it relies on rails/racks, and would be inadvisable to skip these steps.
cd ~/src wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz tar zxvf ./rubygems-1.3.5.tgz cd rubygems-1.3.5 sudo ruby setup.rb
Once Ruby has finished installing RubyGems you can check by verifying it’s version as well as update the repository.
[root@host src]# gem -v 1.3.5 [root@host src]# gem update Updating installed gems Nothing to update [root@host src]# gem update system Updating installed gems Nothing to update
Now to install Rails
sudo gem install rails
I am told by Hongli Lai (co-founder of Phusion) that it is not necessary to install Rails in order to use Phusion Passenger. Rails is only required if you deploy Rails app. So this step can be omitted if so desired.
Now we can finally install passenger
sudo gem install passenger
Now that passenger is installed, we can move onto the installer, which gives us several options regarding the new Nginx build.
Hi kbeezie, good writeup. 🙂 I just published a blog article about Phusion Passenger and Python today. Maybe you’d care to comment? http://izumi.plan99.net/blog/index.php/2009/11/21/phusion-passenger-for-python/
“Well need to download and compile Ruby version 1.9.1 patch level 129. While this is not the latest, Ive had unconfirmed reports that anything newer than p129 is not fully compatible with Passenger.”
This is correct. Later versions of 1.9.1 have bugs in the ‘tempfile’ library. These bugs have been fixed in Ruby’s SVN repository but so far there hasn’t been a 1.9.1 release containing the bug fixes.
By the way, it’s not necessary to install Rails in order to use Phusion Passenger. Rails is only required if you deploy Rails apps.
kbeezie, form some reason sudo is not finding ruby
any ideas?
Without using sudo, try executing ruby -v to see if anything shows up at all, if not try ‘which ruby’. If nothing still shows up then either the PATH isn’t configured correctly to Ruby, or Ruby itself isn’t properly installed. ‘sudo’ itself doesn’t find commands per se, but is simply a way of saying ‘I want to run the following command as a super-user or root’.
Hrm? Why, I’ll assuming that you’ve not seen the uwsgi project? This is much better for python/django/pylons – http://projects.unbit.it/uwsgi/
Good Luck
Note the date of Nginx’s support for uwsgi and the date of said article.