Install Ruby On Rails, Postgres, GitHub, Nginx with Passenger

19 Mar 2017 | category: tech | Comments
#ruby #postgres #git #nginx #rails #devops

To setup production environment with ruby, rails, nginx and passengeruse following steps one by one

  • Install dev dependencies
    
          sudo apt-get install zlib1g zlib1g-dbg zlib1g-dev sqlite3 libsqlite3-dev build-essential openssl libreadline6 libreadline6-dev curl git-core libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion g++ openjdk-6-jdk git nodejs
        
  • Install rvm with latest stable ruby version
    
          curl -L https://get.rvm.io | bash -s stable --ruby
        
  • Edit .bash_profile file and add following file then press Ctrl-D if you are using cat
    
          cat >>~/.bash_profile
          [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
          Ctrl+D
        
  • Latest rubygems
    
          rvm rubygems latest
        
  • Install Rails you can provide versions
    
          sudo gem install rails
        
  • Install postgres
    
          sudo apt-get -y install postgresql libpq-dev
        
  • Installation of Git
    
          sudo apt-get install git
          sudo apt-get update
          which git
          sudo apt-get install git-core
          which git
          git --version
        
  • Git Configuration
    
          git config --global user.name "vishalzambre"
          git config --global user.email v.zambre@gmail.com
          git config –list
        
  • Installation of Nginx
    
          sudo apt-get -y update
          sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core python-software-properties
        
  • Installation of passenger
    
          gem install passenger
          rvmsudo passenger-install-nginx-module
    
          NOTE: Choose "download, compile, and install Nginx for me"
          Accept defaults for any other questions it asks you
        
  • Next we want to setup a script to allow us to control Nginx
    
          wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
          sudo mv init-deb.sh /etc/init.d/nginx
          sudo chmod +x /etc/init.d/nginx
          sudo /usr/sbin/update-rc.d -f nginx defaults
        
  • You can now control Nginx with this script. To start and stop the server manually, you run:
    
          sudo /etc/init.d/nginx stop
          sudo /etc/init.d/nginx start
          We can verify nginx is running by opening up Firefox and going to http://localhost
        
  • Node.js for the Rails asset pipeline
    
          sudo apt-add-repository ppa:chris-lea/node.js
          sudo apt-get -y update
          sudo apt-get -y install nodejs
        
  • Configure Your Rails App
    
          You can modify your /opt/nginx/conf/nginx.conf
          server {
              listen 80;
              server_name example.com;
              root /home/deploy/myapplication/public;   # <--- be sure to point to 'public'!
              passenger_enabled on;
          }
          Just change the application folder name and the server name and then restart the nginx service.
        
  • </ol>