Getting ruby 1.9.1 and nginx and passenger and ubuntu to all play nicely is fairly straightforward, but it’s not just “apt-get” and “gem install” lovin’.
Making ruby 1.9.1 the default ruby is OK. Follow these steps:
Install ruby 1.9.1
sudo apt-get update
sudo apt-get install ruby1.9.1 ruby1.9.1-dev \
rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 \
build-essential nginx libopenssl-ruby1.9.1 libssl-dev zlib1g-dev
sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby1.9.1.1.gz \
--slave /usr/bin/ri ri /usr/bin/ri1.9.1 \
--slave /usr/bin/irb irb /usr/bin/irb1.9.1 \
--slave /usr/bin/rdoc rdoc /usr/bin/rdoc1.9.1
sudo update-alternatives --config ruby
OK, now that we’ve got ruby 1.9.1 and g++, we can build passenger:
sudo gem install passenger
But that throws the executable “passenger-install-nginx-module” into a subdirectory. Exec from there:
cd /var/lib/gems/1.9.1/gems/passenger-2.2.11/bin sudo ./passenger-install-nginx-module
And according to the build script, we’re done!
But we aren’t. At least for me, I needed to
Fix up the configurations
First up /etc/init.d/nginx in a sudo’ed editor, and replace these two lines:
PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/opt/nginx/sbin/nginx
If you fail to do this, you’ll see this error when you run /etc/init.d/nginx restart:
$ sudo /etc/init.d/nginx start Starting nginx: [emerg]: unknown directive "passenger_enabled" in /etc/nginx/sites-enabled/default:32 configuration file /etc/nginx/nginx.conf test failed
This is because /usr/sbin/nginx doesn’t know how to dance Phusion, hence the need to update the init script.
(TODO: there should be an update-alternatives solution to this, but I can’t find a recipe to replace an existing binary)
You also may see this:
Restarting nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok configuration file /opt/nginx/conf/nginx.conf test is successful [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use) [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use) [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use) [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use) [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use) [emerg]: still could not bind() nginx.
Something (most likely apache2) is already listening on port 80. Find out with lsof:
$ sudo lsof -i tcp:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 14790 root 6u IPv4 29964 0t0 TCP *:www (LISTEN) nginx 14798 nobody 6u IPv4 29964 0t0 TCP *:www (LISTEN)
If it’s apache, edit /etc/apache2/ports.conf and shove it to some other port (like 8888) and run /etc/init.d/apache2 restart:
NameVirtualHost *:8888 Listen 8888
Add your rails configuration
In /etc/nginx/sites-enabled/default, in the server { ... } section, add
location /underpants {
root /webapps/underpants/public;
passenger_enabled on;
}
and restart nginx.
Related posts:
- HOWTO: Make system-wide RVM installations work with cron, monit, delayed_job, and passenger
System-wide RVM installations are recommended for production deployments, but because /usr/bin/ruby is no longer the “correct” ruby, you need to tell all your moving parts about RVM. Before installing ruby...... - Quick MacPorts Installation of Ruby on Rails
October 2010 update: I wrote this a while back, before I knew about RVM. The Ruby Version Manager has a bunch of features that makes it better than macports for...... - HOWTO: Force https/SSL for Apache2, Phusion Passenger and Rails
There’s a lot of buzz right now about Firesheep and non-secure Rails applications. This is a pretty simple problem to solve with Apache’s mod_rewrite. If the traffic isn’t on https,...... - Installing CrashPlan on Ubuntu 9.04 Server Edition
Although rsnapshot is super for linux-to-linux backups, I’ve found CrashPlan to work very well as a backup solution for my family’s windows and mac boxes. The CrashPlan installation works pretty......