Set-up Guide for Rails Server on Ubuntu
Create a ubuntu 13.04 machine at desired hosting. I prefer using Digital Ocean for me.
After creating machine, login with root user.
ssh root@123.45.67.89
Create a user named deploy
with sudo permission. We will use this to carry out all operation instead of using root user. Also choose a strong password for your user.
sudo useradd -s /bin/bash -m -d /home/deploy -g root deploy
sudo passwd deploy
sudo usermod -a -G sudo deploy
Logout from your server and run the following command to copy your ssh keys.This will allow you to do a passwordless login via ssh.
ssh-copy-id deploy@123.45.67.89
ssh deploy@123.45.67.89
Run following commands to update packages already installed :
sudo apt-get -y update
sudo apt-get -y upgrade
Installing RVM
sudo apt-get -y install curl
#==========RVM ============
curl -L https://get.rvm.io | bash -s stable
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc
Logout and login again. Check that rvm is suceesfully installed by :
type rvm | head -n 1
# It should return
rvm is a function
Installing Ruby
rvm requirements
rvm install 2.0
gem install bundler --no-ri --no-rdoc
Installing Rails
gem install rails
#== or a specific version of rails ==#
gem install rails -v 4.1.1
Setup unicorn
and nginx
to run rails app. Optionally you can use apache
server but I am following nginx
and unicorn
here
#============ nginx and unicorn ===========
sudo apt-get -y install nginx
sudo apt-get -y install unicorn
Check following commands for other resuirements such as database, imagemagick, redis, memcache etc.
#============ rake===========
sudo apt-get -y install rake
#============ nodejs ===========
sudo apt-get -y install nodejs
#==============Nokogiri Dependency ===============
sudo apt-get -y install libxslt-dev libxml2-dev
#============== Memcached ===============
sudo apt-get install -y memcached
#============== Redis ===============
sudo apt-get install -y redis-server
#============== Rmagick ===============
sudo apt-get -y install imagemagick libmagickwand-dev
#==============Mysql===============
sudo apt-get -y install mysql-server libmysqlclient-dev
#================ Other Dependencies ================
sudo apt-get -y install build-essential libxslt1.1 libxslt1-dev libxml2 ruby-full libcurl4-openssl-dev git-core libpq-dev libreadline5 openssl libreadline6 zlib1g
#================ All in one Go ========================
sudo apt-get -y install rake nodejs libxslt-dev libxml2-dev memcached redis-server imagemagick libmagickwand-dev build-essential libxslt1.1 libxslt1-dev libxml2 ruby-full libopenssl-ruby libcurl4-openssl-dev git-core libffi-ruby rubygems libpq-dev libreadline5 openssl libreadline6 zlib1g mysql-server libmysqlclient-dev libmysql-ruby
Now server is ready for application to be deployed on server. In next post I will write down how can we use Capistrano for deploying application on our server.