Setting Up Passenger with RVM on Ubuntu
Today I'm going to quickly continue the recent trend of logging installation details on this blog for reference and for anyone who cares to read. Today is Phusion Passenger. Passenger is an application server for serving Ruby (Rack) and Python (WSGI, Web Server Gateway Interface) applications. It sits between your app and your web server (either Apache or Nginx). Among other things, it's one of the preferred ways to deploy Rails applications, which are, themselves, Rack apps. We're going to assume here that you already have rvm (and all of its dependencies) installed in your home directory. ls ~/.rvm
should output ".rvm". Anyway, let's begin.
First we install the passenger gem:
gem install passenger
Next we need libcurl openssl
sudo apt-get install -y libcurl4-openssl-dev
Great. Now let's use the passenger installer to install nginx (the process is the same with apache). Make sure you are not in an app directory when you run this (I like to cd ~
first).
rvmsudo passenger-install-nginx-module
rvmsudo runs a command (in a subshell, as usual) as sudo but passes certain environment variables that we need in this case.
Notice the changes that the passenger installer wants you to make to /opt/nginx/conf/nginx.conf. Go ahead and make those. Note: if you have a Rails app, remember to point nginx's root url to the public directory of your application.
Passenger installs nginx in /opt/nginx by default. This is totally fine, but we need a custom start script. Luckily a nice guy named Andrew Carter has tweaked the start script to work for the exact purpose we want. Let's get his script. I like to store it in an /opt/init.d
directory.
sudo mkdir /opt/init.d
sudo su -c "curl https://raw.github.com/ascarter/nginx-ubuntu-rvm/master/nginx > /opt/init.d/nginx"
There we need the su -c
part because otherwise we are "curl-ing" the file as root, but not writing it to the file as root, so we would get a "permission denied".
Awesome. Let's symlink /opt/init.d/nginx to /etc/init.d/nginx since that's where ubuntu likes startup scripts to live.
sudo ln -s /opt/init.d/nginx /etc/init.d/nginx
Note: a symlink will fail if the file already exists. This tutorial assumes you don't already have nginx installed.
Finally, lets give executable permission to the nginx script:
sudo chmod 755 /opt/init.d/nginx
Great. Now we can start nginx and, as long as we have permission to read config files, read, write, and execute necessary files in our app, and bind to the ports we want, all should work.
sudo service nginx start
Notes
- The symlinking part is optional and just preference.
- This post is not quite as rigorously experimented with as usual. Let me know if there are any problems, and I'll edit this when I next install passenger.