Skip to content

Instantly share code, notes, and snippets.

@tshakah
Forked from jcowhigjr/README.md
Last active August 29, 2015 14:14
Show Gist options
  • Save tshakah/f33b026219e7ea1f8f71 to your computer and use it in GitHub Desktop.
Save tshakah/f33b026219e7ea1f8f71 to your computer and use it in GitHub Desktop.
Installing production Rails, Postgres and Nginx on Ubuntu

Setting up Ruby, Rails, Nginx,and PostgreSQL 9 on Ubuntu 14.04 LTS

Last updated: 01 June 2015

Work in progress

sources:

Fix the locale issue

  • Edit /etc/default/locale as sudo.
  • Append LC_ALL="en_GB.UTF-8" at the end of the file, save and quit.
  • sudo locale-gen en_GB en_GB.UTF-8
  • sudo dpkg-reconfigure locales

Install the necessary packages to install rbenv and build Ruby

  • sudo apt-get update
  • sudo apt-get -y install build-essential bison openssl libreadline6 libreadline6-dev curl git-core
  • sudo apt-get -y install zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3
  • sudo apt-get -y install libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev libcurl4-openssl-dev

Install rbenv

  • cd

  • git clone git://github.com/sstephenson/rbenv.git .rbenv

  • echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

  • echo 'eval "$(rbenv init -)"' >> ~/.bashrc

  • exec $SHELL

  • git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

  • echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc

  • exec $SHELL

  • git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

  • git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

  • git clone https://github.com/sstephenson/rbenv-vars.git ~/.rbenv/plugins/rbenv-vars

  • source ~/.bashrc

Install Ruby

  • rbenv install 2.2.0
  • rbenv rehash
  • rbenv global 2.2.0

Stop installing docs

  • echo "gem: --no-ri --no-rdoc" > ~/.gemrc

Install Rails

  • gem install bundler
  • gem install rails -v 4.2.0
  • rbenv rehash

Install Node.js

  • sudo apt-get update
  • sudo apt-get -y install nodejs
  • sudo apt-get install npm

Install Passenger and nginx

Install Phusion's PGP key to verify packages

  • gpg --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
  • gpg --armor --export 561F9B9CAC40B2F7 | sudo apt-key add -

Add HTTPS support to APT

  • sudo apt-get install apt-transport-https

Add the passenger repository

  • sudo sh -c "echo 'deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main' >> /etc/apt/sources.list.d/passenger.list"
  • sudo chown root: /etc/apt/sources.list.d/passenger.list
  • sudo chmod 600 /etc/apt/sources.list.d/passenger.list
  • sudo apt-get update

Install nginx and passenger

  • sudo apt-get install nginx-extras passenger

Install PostgreSQL

  • sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  • wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  • sudo apt-get update
  • sudo apt-get -y install postgresql libpq-dev postgresql-contrib
  • sudo passwd postgres and enter password 2 times
  • su -l postgres
  • psql
postgres=# ALTER USER postgres WITH PASSWORD 'secr3t';
ALTER ROLE
postgres=# CREATE ROLE postgres LOGIN CREATEDB
postgres-# \q
  • Edit /etc/postgresql/9.4/main/pg_hba.conf and find this line:
# Database administrative login by Unix domain socket
local   all             postgres                                peer
  • Change it to this:
# Database administrative login by Unix domain socket
local   all             postgres                                md5
  • /etc/init.d/postgresql restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment