Saturday, April 21, 2012

Deploying a Rails Application on Red Hat Server using RVM, NGINX, Passenger, Oracle, SVN

Using Red Hat? Oracle? SVN (When there's git!)?
Its a pain, here's the answer.

#Add EPEL to yum
rpm -ivh
yum update

# Create the rvm group and add any users who will be using rvm to the group
sudo su -
groupadd rvm

# Start by adding the root user (required to install RVM)
usermod -a -G rvm root

# Then add any other users who need access to to the rvm group and logout of the superuser account

#Now install RVM
curl -L | bash -s stable

#Load RVM:
$ source ~/.rvm/scripts/'rvm'

#install git
rpm -Uvh
sudo yum install --enablerepo=webtatic git

#install ruby - takes some time...
rvm install 1.9.3
rvm use 1.9.3 --default

#install bundler
gem install bundler

gem install rails -v 3.1.0

#fetch the application. Goto your deployment directory and do
svn checkout

#Edit the rails configuration files:

#install Oracle
#Get the instant client packages from Oracle and do the following
sudo rpm -i oracle-instantclient11.2-basic-
sudo rpm -i oracle-instantclient11.2-devel-

#install the gems
bundle install

#Precompile assets
rake assets:precompile RAILS_ENV=production

#create the service_log directory
mkdir log/service_log

#now we need to get some permissions straight
chmod -R 777 tmp
chmod -R 777 log/service_log

#install passenger
gem install passenger

#install nginx. Accept all the defaults
rvmsudo passenger-install-nginx-module

#Here's the nginx conf file /opt/nginx/conf/nginx.conf
#Here are some helpful locations
# passenger_root /usr/local/rvm/gems/ruby-1.9.3-p125/gems/passenger-3.0.12;
# passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.3-p125/ruby;

#Copy the config file
sudo cp /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf.bak
rm /opt/nginx/conf/nginx.conf
cp installation_dump/nginx.conf /opt/nginx/conf/nginx.conf

#update the configurations (eg. the rails app public path, port number, server name etc. and stuff similar to what you might be doing with java web servers)
nano /opt/nginx/conf/nginx.conf

#Copy the nginx start/stop helper script
sudo cp installation_dump/nginx /etc/init.d/

sudo /etc/init.d/nginx start

#Troubleshoot - if you see nothing after start you can debug using
sudo /etc/init.d/nginx configtest

No comments: