Here is my development environment NGINX configuration that allows PHP to run via php-fpm and Ruby on Rails to run with Phusion Passenger in the same server configuration, even under the same domain if you want.

To begin, install Ruby and Rubygems for your distro. This example is using Ubuntu 12.04: Note that the ruby1.9.1 package actually installs ruby 1.9.3 and gems is included in this package.

sudo apt-get install ruby1.9.1

Then install phusion passenger with the command: If this is a brand new server you may also need the build-essential package with compiler tools like make.

sudo gem install passenger

Then install the nginx web server: This command will walk you through downloading nginx source code and compile a new web server with passenger support for you. You may also need to install packages for ruby1.9.1-dev, and libcurl4-openssl-dev

sudo passenger-install-nginx-module

For rails support run:

sudo gem install rails

To get php support install the php5-fpm package for your distro:

sudo apt-get install php5-fpm

Then configure the nginx server to use both php and rails: This configuration sets the nginx user to my username for development. You’ll want to change that to your own development user, or a server account like www-data for production. If your rails app is in a sub folder you’ll need to use the passenger_base_url /railsapp like I have shown here. The /railsapp will be a symlink in your web server root to your rails app’s public folder. I do this for development so I can have other sites under different sub-folders. If your rails app will be the root of your site then you can set the root to the path to the rails public folder.

user pyasi;

worker_processes 1;

error_log logs/error.log;

events {

   worker_connections 1024;


http {

   passenger_root /var/lib/gems/1.9.1/gems/passenger-3.0.18;

   passenger_ruby /usr/bin/ruby1.9.1;

   include mime.types;

   default_type application/octet-stream;

   sendfile on;

   keepalive_timeout 65;

server {

      listen 80;

      server_name localhost;

      root /home/pyasi/www/;

      index index.php index.html index.htm;

      autoindex on;

      rails_env development;

      passenger_enabled on;

      passenger_base_uri /railsapp;

      # pass the PHP scripts to FastCGI server listening on

      location ~* .php {

            fastcgi_split_path_info ^(.+.php)(.*)$;


            fastcgi_index index.php;

            fastcgi_intercept_errors on;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include fastcgi_params;




Then you can start your nginx server by running a command like the one shown that specifies the path to your server and configuration file, or better yet, make a startup script in your init.d

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

Before you setup your first rails app you will also need to install the libsqlite3-dev package for the sqlite bundle and a javascript engine like nodejs which is required by rails.

After installing this in my development machine, I went through my tutorial again on a virtual machine, so I believe I’ve included all the little packages and dependencies you may run into. Let me know in the comments if I’ve missed anything. I hope this tutorial finds you well.