Skip to content

Instantly share code, notes, and snippets.

@Jellyfishboy
Last active November 21, 2017 06:49
Show Gist options
  • Save Jellyfishboy/4809ebb1f821b44a05386f8919c5da2e to your computer and use it in GitHub Desktop.
Save Jellyfishboy/4809ebb1f821b44a05386f8919c5da2e to your computer and use it in GitHub Desktop.
Nginx + Postgresql + rbenv + Rails + Redis + Memcached + Monit || Ubuntu 14+ server setup

Update server

sudo apt-get update

sudo apt-get dist-upgrade

Install system monitoring

sudo apt-get install htop

Install web server

sudo apt-get install nginx

Assign basic HTML web server config

cd /etc/nginx/sites-available

sudo vim template

server {
        listen       80;
        server_name  example.com www.example.com;
        root /home/ubuntu/examplecom;
        index index.html;

        location / {
                try_files $uri $uri/ /index.html?$args;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }
}

sudo ln -s /etc/nginx/sites-available/template /etc/nginx/sites-enabled/template

Install database

sudo apt-get install postgresql postgresql-contrib

Install Git

sudo apt-get install git

Install memcached server

sudo apt-get install memcached

Install Redis server

sudo apt-get install redis-server

Install image processor

sudo apt-get install imagemagick

Install monit

sudo apt-get install monit

Resolve dependencies for 'pg' gem (PostgreSQL)

sudo apt-get install libpq-dev

Add user for deploys

sudo adduser deploy

Grant deploy user sudo access

sudo visudo

deploy ALL=(ALL) NOPASSWD: ALL

Temporarily allow password auth for deploy user

sudo vim /etc/ssh/sshd_config

Match User deploy
    PasswordAuthentication yes
    
sudo service ssh restart

Remove after deploy user has set up ssh key

Now Login as deploy user

Set database user password and privileges

sudo -u postgres psql

CREATE USER "deploy";

ALTER USER "deploy" WITH PASSWORD 'new_password';

ALTER USER "deploy" CREATEDB;

Create SSH key

cd ~/.ssh

sudo vim authorized_keys (copy the public key on your local machine into this file)

sudo service ssh restart

Install Ruby with rbenv

sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

cd

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

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

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

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

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

source ~/.bash_profile 

rbenv install -v 2.3.0

rbenv global 2.3.0

ruby -v

Set up ruby gems

echo "gem: --no-document" > ~/.gemrc

gem install bundler

gem install rails

gem install whenever

rbenv rehash

rails -v

Install Nodejs, Npm and Bower

sudo apt-get install nodejs

sudo ln -s /usr/bin/nodejs /usr/bin/node

sudo apt-get install npm

sudo npm install -g bower

bower -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment