Ubuntu 10.04 with Nginx, Ruby and PHP/PHP-FPM installation: errors and fixes.
May 31, 2011
A few days ago, I signed up for a Linode instance with Ubuntu 10.04 installed on it. The plan is to gradually move all my websites, including this blog to the new instance. I gave NGiNX a shot as my web server after reading a few articles on how it is light and fast, compared to Apache. Here’s what happened.
1. Don’t lock yourself out of your own server:
The server needs to run NGiNX with Ruby on Rails, MySQL, and PHP. I found Chris Kemson’s guide to be the best and started following it.
The installation was fairly smooth, except for one hilarious mistake on my part: I followed the instructions too closely. During the step for installing UFW (Uncomplicated Firewall), Chris asks us to first enable the firewall, and then turn on support for ssh and http. So I went along and turned on the firewall, only to find myself logged out of the ssh session and no way to go back in. First, I laughed pretty hard at myself, and then logged into the Linode control panel to see if there was anything I could do. Thankfully, Linode provides a web-console, which let me log in and allow ssh access through the firewall.
2. Phusion Passenger only speaks in one Ruby at a time
Something I wanted to support was being able to run both Rails 2 and 3. A lot of people seem to recommend installing RVM for this. RVM lets us run multiple versions of ruby on the same system, and switch between them as needed. This means that it is possible to setup Rails 2 under Ruby 1.8.7 and Rails 3 under Ruby 1.9.2. So far so good. The problem is in deployment. You see, Phusion Passenger does not allow us to run multiple versions of Ruby. The line export PATH=/opt/myruby/bin:$PATH is an http level statement in nginx.conf, and specifying a different ruby for each server simply generates an error. I eventually settled with removing RVM, and running Rails 2 and 3, installed under the same Ruby version (1.9.2).
3. Errors with hard to find solutions
Here are a few NGiNX configuration related errors that haunted me:
403: Forbidden / 500: Internal Server error / Completely blank index page.
Going to index.php (the root url) initiates a download of the index.php file
The following fixes seem to work for the above cases:
I like to serve my website out of each user’s public_html directory. Make sure that the public_html directory has the proper permissions to allow NGiNX to access it.
Make sure that the index setting specifies index.php:
index index.html index.htm index.php;
Make sure that your server has the following lines: