There is tons of good installation guide for Rails, but I still think it’s reasonable to log my installation here as I will change it time to time to make this blog ever better.
Part 1, Install Common Rails Passenger environment
Upgrade Ubuntu 12.04 and enable SSH server
sudoapt-getupdate
sudoapt-getupgrade
sudoapt-getinstallopenssh-server
Test SSH and add authorized_keys
mkdir-p~/.ssh
echo'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAsBsQ623fdllkyWBnmIVL9lfaxLGKulWv7jwhxLIhp+3fFZ/K0yGeUoJig6a4UlFFmIPibWiubP7utqvJOZO4psdX+GM42HCU/JZmG3gJqYRgwUMupeb8BXEL4r/nG/YE84kOYh1jF8yjNHs2ZSeaO4M4v7Mcsi8USWTM4mTZhO9HZcQZCQBZbkzCf2PwgNq8q7G9jXq6kU+mpUCbwVFZF1R461lzFOIjZQUvxZ+ylKdZxyX0AGCdLybSPcJJkE/H5FMs5KnInme5/692uz8DjXHi0ddw8s6bfIJI7a9av58kJlZNFu/XDWF7WfoNVRhQWn+cl0eBO+hRlUxMCM8jTw== Eric Guo'>~/.ssh/authorized_keys
Install rvm in root
sudosu# switch to root if not yet
apt-getinstallcurl
curl-Lget.rvm.io|bash-sstable# install rvm
logout# suggest logout and enter again to test rvm works
Install rvm requirement package
rvmrequirements
Read comment output request and copy paste below command:
apt-getinstallbuild-essentialopenssllibreadline6libreadline6-devcurlgit-corezlib1gzlib1g-devlibssl-devlibyaml-devlibsqlite3-devsqlite3libxml2-devlibxslt-devautoconflibc6-devncurses-devautomakelibtoolbisonsubversion# do not copy this line, copy your rvm requirements output
Install MRI Rubies and Rails
rvmlistknown# find your favorate ruby version
rvminstall1.9.3-p194--patchrailsexpress# here is lastest stable version
ruby-v# to verify it is install right
gemupdate--system# upgrade gem package
geminstallrails# install latest stable rails
Install Phusion Passenger and nginx
nginx-v# make sure no nginx install, if install need remove by running gem install passenger
geminstallpassenger
passenger-install-nginx-module# running step by step installer
passenger-install-nginx-module# rerun and enter until you meed below notice
Automatically download and install Nginx?
Nginx doesn't support loadable modules such as some other web servers do,
so in order to install Nginx with Passenger support, it must be recompiled.
Do you want this installer to download, compile and install Nginx for you?
1. Yes: download, compile and install Nginx for me. (recommended)
The easiest way to get started. A stock Nginx 1.2.2 with Passenger
support, but with no other additional third party modules, will be
installed for you to a directory of your choice.
2. No: I want to customize my Nginx installation. (for advanced users)
Choose this if you want to compile Nginx with more third party modules
besides Passenger, or if you need to pass additional options to Nginx's
'configure' script. This installer will 1) ask you for the location of
the Nginx source code, 2) run the 'configure' script according to your
instructions, and 3) run 'make install'.
Whichever you choose, if you already have an existing Nginx configuration file,
then it will be preserved.
Answer 1, install from fresh and accept default install location /opt/nginx
If you see below, you successfully install nginx and Passenger:
Deploying a Ruby on Rails application: an example
Suppose you have a Ruby on Rails application in /somewhere. Add a server block
to your Nginx configuration file, set its root to /somewhere/public, and set
'passenger_enabled on', like this:
server {
listen 80;
server_name www.yourhost.com;
root /somewhere/public; # <--- be sure to point to 'public'!
passenger_enabled on;
}
And that's it! You may also want to check the Users Guide for security and
optimization tips and other useful information:
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.15/doc/Users guide Nginx.html
Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
https://www.phusionpassenger.com
Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
sudoupdate-rc.dnginxdefaults87# enable nginx auto start and 87 is startup number
Configure nginx to enable vhosts (site by site configure file)
logout# as root now
mkdir-pinclude/opt/nginx/conf/vhosts/
chmod755/opt/nginx/conf/vhosts/
vi/opt/nginx/conf/nginx.conf
# comments out all configure entry in server section since you add below
# append 'include /opt/nginx/conf/vhosts/*;' before last } (the http section)
You may also want to set some Passenger parameter like passenger_max_pool_size 15; according to your system status.
Create rails root folder
sudomkdir-p/var/rails_apps
sudochmod777/var/rails_apps/#giving full file permissions
Part 2, Install one application to site
Create per application user (using pl-form as example)
sudoadduser\
--system\
--shell/bin/bash\
--gecos'eForms'\
--group\
--home/home/pl-formpl-form
passwdpl-form# setting application password
Prepare application access and private key
sudosu-pl-form
mkdir-p~/.ssh
echo'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAsBsQ623fdllkyWBnmIVL9lfaxLGKulWv7jwhxLIhp+3fFZ/K0yGeUoJig6a4UlFFmIPibWiubP7utqvJOZO4psdX+GM42HCU/JZmG3gJqYRgwUMupeb8BXEL4r/nG/YE84kOYh1jF8yjNHs2ZSeaO4M4v7Mcsi8USWTM4mTZhO9HZcQZCQBZbkzCf2PwgNq8q7G9jXq6kU+mpUCbwVFZF1R461lzFOIjZQUvxZ+ylKdZxyX0AGCdLybSPcJJkE/H5FMs5KnInme5/692uz8DjXHi0ddw8s6bfIJI7a9av58kJlZNFu/XDWF7WfoNVRhQWn+cl0eBO+hRlUxMCM8jTw== Eric Guo'>~/.ssh/authorized_keys
vi~/.ssh/id_rsa# copy & paste your key here
chmod600~/.ssh/id_rsa
Clone the application source code from git
sudosu-pl-form
cd/var/rails_apps
gitclonegitolite@cvpscmip01:pl-form.git
Install application depend gems
logout# as root now
cd/var/rails_apps/pl-form
bundle# install system gems
Bundle and Migrate database
sudosu-pl-form
cd/var/rails_apps/pl-form
bundle
rakedb:migrate# migrate db
Append application conf to nginx server
logout# as root now
mkdir-p~/confs/nginx
cd~/confs/nginx
vicvpforms# using below nginx conf as example
Sample pl-form nginx configure file
server{
listen80;
server_namecvpforms;# replace your DNS name
rails_envdevelopment;# development or production
root/var/rails_apps/pl-form/public;
passenger_enabledon;
}
Link the configure file and restart nginx
cd/opt/nginx/conf/vhosts
ln-s~/confs/nginx/cvpformscvpforms
cd/var/rails_apps/pl-form
touchtmp/restart.txt# or restart the whole server /etc/init.d/nginx restart
Part 3 Install Oracle Client
Download only instantclient-basic, instantclient-sqlplus and instantclient-sdk zip archives and unzip them all into the same instantclient_11_2 folder. x86x64
Install Oracle Instant Client
sudoapt-getinstalllibaio-dev# must need if you want to use sqlplus
Do not forget to config tnsnames.ora at /opt/oracle/instantclient_11_2/network/admin and running sqlplus to ensure oracle client can link to the database correctly.
install ruby-oci8 gems now
geminstallruby-oci8# should be no any error here :-)