How to upgrade Phusion Passenger for nginx

I keep forgetting the procedure to upgrade Passenger and nginx, so thought I'd note them down here in case anyone finds it useful. These instructions assume that:

Upgrade

Download the latest nginx source and uncompress to a temporary directory.

1
2
3
cd ~/sources
wget http://sysoev.ru/nginx/nginx-0.7.64.tar.gz
tar xzvf nginx-0.7.64.tar.gz

Install the latest Passenger gem

1
sudo /opt/ruby-enterprise-1.8.6-20090520/bin/gem install passenger

Run the Passenger installer

1
sudo /opt/ruby-enterprise-1.8.6-20090520/bin/passenger-install-nginx-module

Follow the onscreen instructions, choose option 2 to use your own sources. Specify the location of the nginx sources when prompted.

If you want to use any other optional nginx modules, enable them when prompted. I want to use the SSL and Status modules, so I enable them like this:

1
--with-http_ssl_module --with-http_stub_status_module

The full configure line will look something like this:

1
2
3
./configure --prefix='/opt/nginx' --with-pcre='/tmp/pcre-7.8'
--add-module='/opt/ruby-enterprise-1.8.6-20090520/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/nginx'
--with-http_ssl_module --with-http_stub_status_module

After the installer has finished, the new version will be installed in /opt/nginx and the old version will be renamed to nginx.old.

Configure

Update the nginx.conf with the correct paths, you should only need to change the path to the passenger_root directive.

1
2
3
4
5
http {
    ...
    passenger_root /opt/ruby-enterprise-1.8.6-20090520/lib/ruby/gems/1.8/gems/passenger-2.2.5;
    ...
}

Restart

I like to do a config file syntax check before I restart nginx, just in case of typos and the like.

1
sudo /opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf

If the check is successful, restart nginx.

1
sudo /etc/init.d/nginx restart

You should now be running the latest version of Passenger and nginx.