llygiw
Last Updated: February 25, 2016
·
110
· devatotech

Setup Generic Rails Server for Staging (WIP)

Initial Setup

Login as root and run these to get things started:

apt-get update
apt-get upgrade

Create a user:

adduser deploy

and setup .ssh directory:
mkdir /home/deploy/.ssh chmod 700 /home/deploy/.ssh

Next, create an authorized_keys file:

vim /home/deploy/.ssh/authorized_keys

Keep that tab open, open a new tab to run locally and copy your public key:

pbcopy < ~/.ssh/id_rsa.pub

Then add it to the server auth keys.

NEXT, Set permissions for deploy:

chmod 400 /home/deploy/.ssh/authorized_keys
chown deploy:deploy /home/deploy -R

Finally add deploy to the /etc/sudoers:

vim /etc/sudoers

Add this line under root:

deploy ALL=(ALL) NOPASSWD: ALL

Now you can restart the ssh server:

service ssh restart

And logout of root. LOGIN as deploy to continue.

Dependencies

Login as deploy and run these commands:
sudo apt-get install curl git-core build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev libcurl4-openssl-dev libffi-dev

Install Ruby 2.2.0

Once you run make below it will take some time to process:
wget https://ftp.ruby-lang.org/pub/ruby/ruby-2.2.0.tar.gz tar -zxf ruby-2.2.0.tar.gz cd ruby-2.2.0 ./configure make sudo make install

Disable docs on the server:

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

Install bundler:

sudo gem install bundler

Install Memcached (Optional)

sudo apt-get install memcached

Install Nginx (Optional)

sudo apt-get install nginx
sudo service nginx start

Customize nginx default

vim /etc/nginx/sites-enabled/default

Hit dd do go to beginning of file, then dG to delete all.

Then add and customize the nginx conf:

upstream unicorn {
  server unix:/home/deploy/apps/rsscom/shared/system/unicorn.sock fail_timeout=0;
}

server {
  server_name rss.com;
  rewrite ^(.*)$ $scheme://www.rss.com;
}

server {
  listen 80 default deferred;
  server_name www.rss.com;
  root /home/deploy/apps/rsscom/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control 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;
}
Awesome Job

Frontend Web Developer for Games
·
Leamington Spa (United Kingdom)
·
Full Time