This article will show you how to deploy a ruby on rails application in local environment with RVM, Homebrew, Passenger & Nginx on Mac OS X.
You need some basic knowledge about RVM and homebrew, don’t worry, it’s very easy and just make u happy.
###RVM & Ruby
Ruby Version Manager, you can use it to install and manage multiple versions of ruby, there is a use guide in Chinese write easy. http://lanvige.com/posts/rvm_guide_cn/
We will use
ruby-1.9.3-p0 & rails 3.1.3 in this demo.
Homebrew is the best software install & manage tool on OS X, it also fixed the dependent issue. more about homebrew, see: http://lanvige.com/posts/homebrew_in_action/
Install the least version of rails, current version 3.1.3
Install Passenger gem, version 3.0.11
####Build with passenger module
Then use brew to install the least version of nginx.
Because we need passenger as application work with nginx, you can build the passenger module later, but brew already provide a argument to build nginx with passenger module, use below line instead.
After the nginx build and install successfuly, there will be a brief introduction to configure the init with system, and use launchctl load to start the nginx right now.
####Nginx Config File
Homebrew set all the app’s config file at /usr/local/etc/ folder replace /ect/, so edit the
/usr/local/etc/nginx/nginx.conf file to add ruby and applications’ info.
####There are a few things to note:
The first line set which user should nginx run as.
passenger_root to point the passenger path, you can run below line to get the path:
passenger_ruby, the first line set nginx run as staff, not current user, so nginx will can’t find the rails because we never added the rvm to staff’s shell environment, but we have wrapper, it will set ruby/rails/… ‘s path to shell.
include, It’s a best practice to split every site’s config to a single file then combine with include.
####Site Config File
It’s a minest config file with a rails site.
listen 8080, we just can use the number bit than 1024 as port to listen, because brew always use current as owner to run the application.
root, the root point to the public folder of your rails application.
rails_evn, this config what environment will run as.
Check the Config file with -t parameters.
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Add the lanvige.local to your /etc/hosts so the browser can find the site with name.
http://lanvige.local:8080/ in your browser try to open the rails site, no accidents, browser will show your rails home page normally.
####Upgraded the passenger
If you run gem update passenger to upgrade a new Passenger version, then need do the follow steps to make sure the new passenger works well.
update the passenger_root to new passenger root in Nginx config file.
Rebuild the PassengerWatchdog
The rails application site work again.
###Upgraded the Nginx
I’m not sure the upgrade will add –with-passenger automatically when you run brew upgrade nginx, and you can’t just build a module for nginx, it means if you want add a new module you need rebuild all nginx source.
I’ll check this later.
Update on 21 Dec 2011, It works! use below line to upgrade nginx with passenger.
###More about the init port:
Why we can’t use 80 port with nginx installed by brew.
Notice that the username is samsoffes and not root. Using the root user is considered bad practice by most. (We’ll create that user in the next step.)Note: you need to make your user a superuser for your tests to run correctly. More on this?here.
###Install Passenger Manual