Skip to content

Instantly share code, notes, and snippets.

@bitkidd
Forked from ChuckJHardy/digital_ocean_setup.md
Last active February 15, 2016 19:10
Show Gist options
  • Save bitkidd/2081aab3afe8ab8101a6 to your computer and use it in GitHub Desktop.
Save bitkidd/2081aab3afe8ab8101a6 to your computer and use it in GitHub Desktop.

Revisions

  1. Kirill Ross revised this gist Feb 15, 2016. 1 changed file with 2 additions and 7 deletions.
    9 changes: 2 additions & 7 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -33,15 +33,10 @@ SSH with Deploy User (Don't close root)

    $ ssh -p 1026 [email protected]

    Install Curl and build stuff

    $ sudo apt-get update
    $ sudo apt-get install curl gnupg build-essential

    Install RVM
    Install RVM, ImageMagick and other stuff

    $ sudo apt-get update
    $ 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 libgmp-dev libmagickwand-dev imagemagick libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
    $ sudo apt-get install curl gnupg build-essential 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 libgmp-dev libmagickwand-dev imagemagick libgdbm-dev libncurses5-dev automake libtool bison libffi-dev

    $ cd
    $ curl -L https://get.rvm.io | bash -s stable
  2. Kirill Ross revised this gist Feb 15, 2016. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -41,10 +41,9 @@ Install Curl and build stuff
    Install RVM

    $ sudo apt-get update
    $ 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 libgmp-dev
    $ 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 libgmp-dev libmagickwand-dev imagemagick libgdbm-dev libncurses5-dev automake libtool bison libffi-dev

    $ cd
    $ sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
    $ curl -L https://get.rvm.io | bash -s stable

    It may ask you to add signatures, add them and repeat last step
    @@ -77,7 +76,6 @@ Install NVM + Node.js, latest version ov NVM was 0.30.0, go check the latest one
    Install Rails

    $ gem install rails -v 4.2.4
    $ rbenv rehash
    $ rails -v
    # Rails 4.2.4

  3. Kirill Ross revised this gist Jan 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ### Ubuntu 14.04 x64 + RVM + Node.js + Rails 4 + Nginx + Passenger + PostgreSQL
    ### Ubuntu 14.04 x64 + RVM + NVM + Node.js + Rails 4 + Nginx + Passenger + PostgreSQL

    SSH into Root

  4. Kirill Ross revised this gist Jan 12, 2016. 1 changed file with 14 additions and 5 deletions.
    19 changes: 14 additions & 5 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -59,11 +59,20 @@ Install Bundler
    $ echo "gem: --no-ri --no-rdoc" > ~/.gemrc
    $ gem install bundler

    Install Node.js

    $ curl -sL https://deb.nodesource.com/setup | sudo bash -
    $ sudo apt-get install nodejs
    $ sudo apt-get install build-essential
    Install NVM + Node.js, latest version ov NVM was 0.30.0, go check the latest one here: https://github.com/creationix/nvm

    $ curl https://raw.githubusercontent.com/creationix/nvm/v0.30.0/install.sh | sh
    $ source ~/.profile
    $ nvm ls-remote
    . . .
    v4.2.3
    v4.2.4
    v5.0.0
    v5.1.0
    . . .
    $ nvm install 4.2.4
    $ nvm use 4.2.4
    $ node -v

    Install Rails

  5. Kirill Ross revised this gist Dec 20, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -105,11 +105,11 @@ Getting passenger_ruby (nginx)

    $ passenger-config about ruby-command
    passenger-config was invoked through the following Ruby interpreter:
    Command: /home/deployer/.rbenv/versions/2.2.3/bin/ruby
    Command: /home/deployer/.rvm/gems/ruby-2.2.3/wrappers/ruby
    Version: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
    To use in Apache: PassengerRuby /home/deployer/.rbenv/versions/2.2.3/bin/ruby
    To use in Nginx : passenger_ruby /home/deployer/.rbenv/versions/2.2.3/bin/ruby
    To use with Standalone: /home/deployer/.rbenv/versions/2.2.3/bin/ruby /usr/bin/passenger start
    To use in Apache: PassengerRuby /home/deployer/.rvm/gems/ruby-2.2.3/wrappers/ruby
    To use in Nginx : passenger_ruby /home/deployer/.rvm/gems/ruby-2.2.3/wrappers/ruby
    To use with Standalone: /home/deployer/.rvm/gems/ruby-2.2.3/wrappers/ruby /usr/bin/passenger start

    Getting passenger_root

  6. Kirill Ross revised this gist Dec 20, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ Install Curl and build stuff
    Install RVM

    $ sudo apt-get update
    $ 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
    $ 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 libgmp-dev

    $ cd
    $ sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
  7. Kirill Ross revised this gist Dec 20, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -62,7 +62,6 @@ Install Bundler
    Install Node.js

    $ curl -sL https://deb.nodesource.com/setup | sudo bash -
    $ sudo apt-get update
    $ sudo apt-get install nodejs
    $ sudo apt-get install build-essential

  8. Kirill Ross revised this gist Dec 20, 2015. 1 changed file with 12 additions and 16 deletions.
    28 changes: 12 additions & 16 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ### Ubuntu 14.04 x64 + Rbenv + Node.js + Rails 4 + Nginx + Passenger + PostgreSQL
    ### Ubuntu 14.04 x64 + RVM + Node.js + Rails 4 + Nginx + Passenger + PostgreSQL

    SSH into Root

    @@ -29,7 +29,7 @@ Reload SSH (Optional)

    $ reload ssh
    SSH with Deploy User (Don't close root) (Optional)
    SSH with Deploy User (Don't close root)

    $ ssh -p 1026 [email protected]

    @@ -38,25 +38,20 @@ Install Curl and build stuff
    $ sudo apt-get update
    $ sudo apt-get install curl gnupg build-essential

    Install RBENV
    Install RVM

    $ sudo apt-get update
    $ 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"' >> ~/.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
    $ sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
    $ curl -L https://get.rvm.io | bash -s stable

    It may ask you to add signatures, add them and repeat last step

    $ rbenv install 2.2.3
    $ rbenv global 2.2.3
    $ source ~/.rvm/scripts/rvm
    $ rvm install 2.2.3
    $ rvm use 2.2.3 --default
    $ ruby -v

    Install Bundler
    @@ -66,9 +61,10 @@ Install Bundler

    Install Node.js

    $ sudo add-apt-repository ppa:chris-lea/node.js
    $ curl -sL https://deb.nodesource.com/setup | sudo bash -
    $ sudo apt-get update
    $ sudo apt-get install nodejs
    $ sudo apt-get install build-essential

    Install Rails

  9. Kirill Ross revised this gist Dec 20, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -25,11 +25,11 @@ Configure SSH (Optional)
    UseDNS no # Add
    AllowUsers deployer # Add

    Reload SSH
    Reload SSH (Optional)

    $ reload ssh
    SSH with Deploy User (Don't close root)
    SSH with Deploy User (Don't close root) (Optional)

    $ ssh -p 1026 [email protected]

  10. Kirill Ross revised this gist Dec 17, 2015. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -12,12 +12,11 @@ Add Deploy User

    $ adduser deployer

    Update Sudo Privileges
    Add Deployer to sudo group

    $ visudo
    username ALL=(ALL:ALL) ALL
    $ adduser deployer sudo

    Configure SSH
    Configure SSH (Optional)

    $ nano /etc/ssh/sshd_config
    Port 22 # Change (1025..65536)
  11. Chirill Ceban revised this gist Nov 6, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ### Ubuntu 14.04 x64 + Rbenv + Node.js + Rails 4 + Nginx + Passenger + PostgreSQL + Capistrano 3
    ### Ubuntu 14.04 x64 + Rbenv + Node.js + Rails 4 + Nginx + Passenger + PostgreSQL

    SSH into Root

  12. Chirill Ceban revised this gist Nov 6, 2015. 1 changed file with 41 additions and 180 deletions.
    221 changes: 41 additions & 180 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -34,10 +34,10 @@ SSH with Deploy User (Don't close root)

    $ ssh -p 1026 [email protected]

    Install Curl
    Install Curl and build stuff

    $ sudo apt-get update
    $ sudo apt-get install curl
    $ sudo apt-get install curl gnupg build-essential

    Install RBENV

    @@ -97,190 +97,51 @@ Install GIT

    $ sudo apt-get install git-core

    Setup Nginx

    $ sudo apt-get install nginx
    $ nginx -h
    $ cat /etc/init.d/nginx
    $ /etc/init.d/nginx -h
    $ sudo service nginx start
    $ sudo vim /etc/nginx/sites-enabled/default

    upstream unicorn {
    server unix:/tmp/unicorn.MYAPP.sock fail_timeout=0;
    }

    server {
    listen 80 default deferred;
    # server_name example.com;
    root /home/deployer/apps/MYAPP/current/public;

    location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    }

    location ~ ^/(robots.txt|sitemap.xml.gz)/ {
    root /home/deployer/apps/MYAPP/current/public;
    }

    try_files $uri/index.html $uri @unicorn;
    location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
    }

    Add Unicorn

    $ vim Gemfile
    gem 'unicorn'

    Update Unicorn Config

    $ vim config/unicorn/production.rb

    root = "/home/deployer/apps/MYAPP/current"
    working_directory root

    pid "#{root}/tmp/pids/unicorn.pid"

    stderr_path "#{root}/log/unicorn.log"
    stdout_path "#{root}/log/unicorn.log"

    worker_processes Integer(ENV['WEB_CONCURRENCY'])
    timeout 30
    preload_app true

    listen '/tmp/unicorn.spui.sock', backlog: 64

    before_fork do |server, worker|
    Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
    end
    Install Passenger

    defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
    end

    after_fork do |server, worker|
    Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
    end

    defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
    end

    # Force the bundler gemfile environment variable to
    # reference the capistrano "current" symlink
    before_exec do |_|
    ENV['BUNDLE_GEMFILE'] = File.join(root, 'Gemfile')
    end

    Add Capistrano

    $ vim Gemfile
    $ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
    $ sudo apt-get install -y apt-transport-https ca-certificates

    group :development do
    gem 'capistrano-rails'
    gem 'capistrano-rvm'
    gem 'capistrano3-unicorn'
    end

    Install Capistrano

    $ bundle exec cap install

    Update Capistrano Capfile

    $ vim Capfile

    require 'capistrano/setup'
    require 'capistrano/deploy'
    require 'capistrano/rvm'
    require 'capistrano/bundler'
    require 'capistrano/rails/assets'
    require 'capistrano/rails/migrations'
    require 'capistrano3/unicorn'
    $ sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list'
    $ sudo apt-get update

    # Load custom tasks from `lib/capistrano/tasks' if you have any defined
    Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
    $ sudo apt-get install -y nginx-extras passenger

    Update Capistrano Deploy Config

    $ vim config/deploy.rb

    lock '3.3.5'

    set :application, 'spui'
    set :repo_url, '[email protected]:MYGITHUB/MYAPP.git'

    ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call

    set :use_sudo, false
    set :bundle_binstubs, nil
    set :linked_files, fetch(:linked_files, []).push('config/database.yml')
    set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')

    after 'deploy:publishing', 'deploy:restart'

    namespace :deploy do
    task :restart do
    invoke 'unicorn:reload'
    end
    end
    Getting passenger_ruby (nginx)

    $ passenger-config about ruby-command
    passenger-config was invoked through the following Ruby interpreter:
    Command: /home/deployer/.rbenv/versions/2.2.3/bin/ruby
    Version: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
    To use in Apache: PassengerRuby /home/deployer/.rbenv/versions/2.2.3/bin/ruby
    To use in Nginx : passenger_ruby /home/deployer/.rbenv/versions/2.2.3/bin/ruby
    To use with Standalone: /home/deployer/.rbenv/versions/2.2.3/bin/ruby /usr/bin/passenger start

    Getting passenger_root

    $ passenger-config --root
    /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini

    Edit Nginx config and setup Passenger

    $ sudo nano /etc/nginx/nginx.conf

    Update Production Deploy Config

    $ vim config/deploy/production.rb

    set :port, 22
    set :user, 'deployer'
    set :deploy_via, :remote_cache
    set :use_sudo, false

    server '123.333.333.333',
    roles: [:web, :app, :db],
    port: fetch(:port),
    user: fetch(:user),
    primary: true

    set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"

    set :ssh_options, {
    forward_agent: true,
    auth_methods: %w(publickey),
    user: 'deployer',
    }

    set :rails_env, :production
    set :conditionally_migrate, true

    Add SSH Key to DigitalOcean

    $ cat ~/.ssh/id_rsa.pub | ssh -p 22 [email protected] 'cat >> ~/.ssh/authorized_keys'
    Uncomment these lines and copy passenger_ruby & passenger_root got above

    # passenger_root /some-filename/locations.ini;
    # passenger_ruby /usr/bin/passenger_free_ruby;

    Say Hi to Github
    Add Nginx site

    # follow the steps in this guide if receive permission denied(public key)
    # https://help.github.com/articles/error-permission-denied-publickey
    $ ssh [email protected]
    $ sudo nano /etc/nginx/sites-enabled/myapp.conf
    server {
    listen 80;
    server_name yourserver.com;

    Check Deployment (Commit and Push)
    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/myapp/code/public;

    $ cap production deploy:check

    Deploy

    $ cap production deploy

    Thanks to [James Dullaghan](https://gist.github.com/JamesDullaghan/5941259) for his help.
    # Turn on Passenger
    passenger_enabled on;
    }
  13. Chirill Ceban revised this gist Nov 6, 2015. 1 changed file with 38 additions and 12 deletions.
    50 changes: 38 additions & 12 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -44,17 +44,47 @@ Install RBENV
    $ sudo apt-get update
    $ 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

    $ curl -L get.rvm.io | bash -s stable
    $ source ~/.rvm/scripts/rvm
    $ rvm requirements
    $ rvm install 2.2.0
    $ rvm use 2.2.0 --default
    $ rvm rubygems current
    $ 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

    $ rbenv install 2.2.3
    $ rbenv global 2.2.3
    $ ruby -v

    Install Bundler

    $ echo "gem: --no-ri --no-rdoc" > ~/.gemrc
    $ gem install bundler

    Install Node.js

    $ sudo add-apt-repository ppa:chris-lea/node.js
    $ sudo apt-get update
    $ sudo apt-get install nodejs

    Install Rails

    $ gem install rails -v 4.2.4
    $ rbenv rehash
    $ rails -v
    # Rails 4.2.4

    Install PostgreSQL

    $ sudo apt-get install postgresql postgresql-server-dev-9.3
    $ gem install pg -- --with-pg-config=/usr/bin/pg_config
    $ sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
    $ wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
    $ sudo apt-get update
    $ sudo apt-get install postgresql-common
    $ sudo apt-get install postgresql-9.3 libpq-dev

    Create Postgres User

    @@ -67,10 +97,6 @@ Install GIT

    $ sudo apt-get install git-core

    Install Bundler

    $ gem install bundler

    Setup Nginx

    $ sudo apt-get install nginx
  14. Chirill Ceban revised this gist Nov 6, 2015. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ Update Sudo Privileges

    Configure SSH

    $ vi /etc/ssh/sshd_config
    $ nano /etc/ssh/sshd_config
    Port 22 # Change (1025..65536)
    Protocol 2 # Change
    PermitRootLogin no # Change
    @@ -39,7 +39,10 @@ Install Curl
    $ sudo apt-get update
    $ sudo apt-get install curl

    Install RVM
    Install RBENV

    $ sudo apt-get update
    $ 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

    $ curl -L get.rvm.io | bash -s stable
    $ source ~/.rvm/scripts/rvm
  15. Chirill Ceban renamed this gist Nov 5, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions digital_ocean_setup.md → rails_passenger_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

    #### [Create a Droplet](https://www.digitalocean.com/community/tutorials/how-to-create-your-first-digitalocean-droplet-virtual-server)
    ### Ubuntu 14.04 x64 + Rbenv + Node.js + Rails 4 + Nginx + Passenger + PostgreSQL + Capistrano 3

    SSH into Root

  16. @ChuckJHardy ChuckJHardy revised this gist Dec 30, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions digital_ocean_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

    #### [Create a Droplet](https://www.digitalocean.com/community/tutorials/how-to-create-your-first-digitalocean-droplet-virtual-server)

    SSH into Root

    $ ssh [email protected]
  17. @ChuckJHardy ChuckJHardy revised this gist Dec 30, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion digital_ocean_setup.md
    Original file line number Diff line number Diff line change
    @@ -165,7 +165,6 @@ Add Capistrano
    gem 'capistrano-rails'
    gem 'capistrano-rvm'
    gem 'capistrano3-unicorn'
    gem 'capistrano-sidekiq'
    end

    Install Capistrano
  18. @ChuckJHardy ChuckJHardy revised this gist Dec 27, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions digital_ocean_setup.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + NGINX + Unicorn + PostgreSQL + Capistrano 3
    ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

    SSH into Root

    @@ -68,7 +68,7 @@ Install Bundler

    $ gem install bundler

    Setup NGINX
    Setup Nginx

    $ sudo apt-get install nginx
    $ nginx -h
  19. @ChuckJHardy ChuckJHardy revised this gist Dec 27, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions digital_ocean_setup.md
    Original file line number Diff line number Diff line change
    @@ -239,20 +239,20 @@ Update Production Deploy Config

    Add SSH Key to DigitalOcean

    cat ~/.ssh/id_rsa.pub | ssh -p 22 [email protected] 'cat >> ~/.ssh/authorized_keys'
    $ cat ~/.ssh/id_rsa.pub | ssh -p 22 [email protected] 'cat >> ~/.ssh/authorized_keys'

    Say Hi to Github

    # follow the steps in this guide if receive permission denied(public key)
    # https://help.github.com/articles/error-permission-denied-publickey
    ssh [email protected]
    $ ssh [email protected]

    Check Deployment (Commit and Push)

    cap production deploy:check
    $ cap production deploy:check

    Deploy

    cap production deploy
    $ cap production deploy

    Thanks to [James Dullaghan](https://gist.github.com/JamesDullaghan/5941259) for his help.
  20. @ChuckJHardy ChuckJHardy revised this gist Dec 27, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion digital_ocean_setup.md
    Original file line number Diff line number Diff line change
    @@ -159,6 +159,8 @@ Update Unicorn Config

    Add Capistrano

    $ vim Gemfile

    group :development do
    gem 'capistrano-rails'
    gem 'capistrano-rvm'
    @@ -168,7 +170,7 @@ Add Capistrano

    Install Capistrano

    bundle exec cap install
    $ bundle exec cap install

    Update Capistrano Capfile

  21. @ChuckJHardy ChuckJHardy created this gist Dec 27, 2014.
    256 changes: 256 additions & 0 deletions digital_ocean_setup.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,256 @@
    ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + NGINX + Unicorn + PostgreSQL + Capistrano 3

    SSH into Root

    $ ssh [email protected]

    Change Root Password

    $ passwd

    Add Deploy User

    $ adduser deployer

    Update Sudo Privileges

    $ visudo
    username ALL=(ALL:ALL) ALL

    Configure SSH

    $ vi /etc/ssh/sshd_config
    Port 22 # Change (1025..65536)
    Protocol 2 # Change
    PermitRootLogin no # Change
    UseDNS no # Add
    AllowUsers deployer # Add

    Reload SSH

    $ reload ssh
    SSH with Deploy User (Don't close root)

    $ ssh -p 1026 [email protected]

    Install Curl

    $ sudo apt-get update
    $ sudo apt-get install curl

    Install RVM

    $ curl -L get.rvm.io | bash -s stable
    $ source ~/.rvm/scripts/rvm
    $ rvm requirements
    $ rvm install 2.2.0
    $ rvm use 2.2.0 --default
    $ rvm rubygems current

    Install PostgreSQL

    $ sudo apt-get install postgresql postgresql-server-dev-9.3
    $ gem install pg -- --with-pg-config=/usr/bin/pg_config

    Create Postgres User

    $ sudo -u postgres psql
    create user deployer with password 'password';
    alter role deployer superuser createrole createdb replication;
    create database MYAPP_production owner deployer;

    Install GIT

    $ sudo apt-get install git-core

    Install Bundler

    $ gem install bundler

    Setup NGINX

    $ sudo apt-get install nginx
    $ nginx -h
    $ cat /etc/init.d/nginx
    $ /etc/init.d/nginx -h
    $ sudo service nginx start
    $ sudo vim /etc/nginx/sites-enabled/default

    upstream unicorn {
    server unix:/tmp/unicorn.MYAPP.sock fail_timeout=0;
    }

    server {
    listen 80 default deferred;
    # server_name example.com;
    root /home/deployer/apps/MYAPP/current/public;

    location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    }

    location ~ ^/(robots.txt|sitemap.xml.gz)/ {
    root /home/deployer/apps/MYAPP/current/public;
    }

    try_files $uri/index.html $uri @unicorn;
    location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
    }

    Add Unicorn

    $ vim Gemfile
    gem 'unicorn'

    Update Unicorn Config

    $ vim config/unicorn/production.rb

    root = "/home/deployer/apps/MYAPP/current"
    working_directory root

    pid "#{root}/tmp/pids/unicorn.pid"

    stderr_path "#{root}/log/unicorn.log"
    stdout_path "#{root}/log/unicorn.log"

    worker_processes Integer(ENV['WEB_CONCURRENCY'])
    timeout 30
    preload_app true

    listen '/tmp/unicorn.spui.sock', backlog: 64

    before_fork do |server, worker|
    Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
    end

    defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
    end

    after_fork do |server, worker|
    Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
    end

    defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
    end

    # Force the bundler gemfile environment variable to
    # reference the capistrano "current" symlink
    before_exec do |_|
    ENV['BUNDLE_GEMFILE'] = File.join(root, 'Gemfile')
    end

    Add Capistrano

    group :development do
    gem 'capistrano-rails'
    gem 'capistrano-rvm'
    gem 'capistrano3-unicorn'
    gem 'capistrano-sidekiq'
    end

    Install Capistrano

    bundle exec cap install

    Update Capistrano Capfile

    $ vim Capfile

    require 'capistrano/setup'
    require 'capistrano/deploy'
    require 'capistrano/rvm'
    require 'capistrano/bundler'
    require 'capistrano/rails/assets'
    require 'capistrano/rails/migrations'
    require 'capistrano3/unicorn'

    # Load custom tasks from `lib/capistrano/tasks' if you have any defined
    Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

    Update Capistrano Deploy Config

    $ vim config/deploy.rb

    lock '3.3.5'

    set :application, 'spui'
    set :repo_url, '[email protected]:MYGITHUB/MYAPP.git'

    ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call

    set :use_sudo, false
    set :bundle_binstubs, nil
    set :linked_files, fetch(:linked_files, []).push('config/database.yml')
    set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')

    after 'deploy:publishing', 'deploy:restart'

    namespace :deploy do
    task :restart do
    invoke 'unicorn:reload'
    end
    end

    Update Production Deploy Config

    $ vim config/deploy/production.rb

    set :port, 22
    set :user, 'deployer'
    set :deploy_via, :remote_cache
    set :use_sudo, false

    server '123.333.333.333',
    roles: [:web, :app, :db],
    port: fetch(:port),
    user: fetch(:user),
    primary: true

    set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"

    set :ssh_options, {
    forward_agent: true,
    auth_methods: %w(publickey),
    user: 'deployer',
    }

    set :rails_env, :production
    set :conditionally_migrate, true

    Add SSH Key to DigitalOcean

    cat ~/.ssh/id_rsa.pub | ssh -p 22 [email protected] 'cat >> ~/.ssh/authorized_keys'

    Say Hi to Github

    # follow the steps in this guide if receive permission denied(public key)
    # https://help.github.com/articles/error-permission-denied-publickey
    ssh [email protected]

    Check Deployment (Commit and Push)

    cap production deploy:check

    Deploy

    cap production deploy

    Thanks to [James Dullaghan](https://gist.github.com/JamesDullaghan/5941259) for his help.