https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart
# Create new user with sudo
adduser develop
usermod -aG sudo develop
# Configure sudo for call it without password
# http://askubuntu.com/questions/235084/how-do-i-remove-ubuntus-password-requirement
# Edit the sudoers file:
sudo visudo
# Find this line:
sudo ALL=(ALL) ALL
# Change the line:
sudo ALL=(ALL) NOPASSWD: ALL
# Copy authorized keys
mkdir /home/develop/.ssh
cp ~/.ssh/authorized_keys /home/develop/.ssh/authorized_keys
chown -R develop:develop /home/develop/.ssh
# System update
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
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# Install ruby-build
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
# Check rbenv
rbenv -v
# Install ruby
rbenv install -v 2.2.3
rbenv global 2.2.3
# Config gem
echo "gem: --no-document" > ~/.gemrc
# Install bundler
gem install bundler
# Install Javascript Runtime
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get install nodejs
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-14-04 https://www.howtoforge.com/tutorial/how-to-install-postgresql-95-on-ubuntu-12_04-15_10/
# Add the PostgreSQL repository
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 -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
sudo apt-get update
# Install PostgreSQL
sudo apt-get install postgresql postgresql-contrib
# Switch to postgres user
sudo -i -u postgres
# Enter to postgres console
psql
# Create new postgres user
CREATE USER username WITH PASSWORD 'password';
ALTER USER username CREATEUSER CREATEDB;
# Change connect postgres access
sudo vi /etc/postgresql/9.5/main/pg_hba.conf
# Replace it
local all all md5
# Restart it
sudo /etc/init.d/postgresql restart
# Install it for pg gem support
sudo apt-get install libpq-dev
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-14-04-lts
# Install nginx
sudo apt-get install nginx
# Change default config
sudo vi /etc/nginx/sites-enabled/default
# Restart it
sudo service nginx restart
Simple nginx config
upstream app {
# Path to Puma SOCK file, as defined previously
server unix://srv/servername/shared/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name servername;
# listen 443 ssl;
# ssl_certificate /home/username/ssl/servicename.chained.crt;
# ssl_certificate_key /home/username/ssl/server.key;
root /srv/servername/current/public;
try_files $uri/index.html $uri @app;
location @app {
proxy_pass http://app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
sudo mkdir -p "/srv/servername/" && sudo chown -R develop:develop "/srv/servername/"
mina setup
mina deploy
vi /srv/servername/shared/config/puma.rb
mkdir /srv/servername/shared/sockets
mkdir /srv/servername/shared/pids
Simple puma config
# Change to match your CPU core count
workers 1
# Min and Max threads per worker
threads 1, 6
app_dir = "/srv/servername"
shared_dir = "#{app_dir}/shared"
# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env
# Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"
# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true
# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app
on_worker_boot do
require "active_record"
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/current/config/database.yml")[rails_env])
end
# Install runit
sudo apt-get install runit
# Create service
cd /etc/sv
sudo mkdir servicename
cd servicename
sudo touch run
sudo chmod 775 run
sudo vi run
# Create symlink and run service
sudo ln -s /etc/sv/servicename /etc/service/servicename
# Check log for errors
sudo tailf /var/log/upstart/runsvdir.log
Simple runit config
#!/bin/bash
exec 2>&1
export RBENV_ROOT="/home/develop/.rbenv"
export PATH="/home/develop/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export RAILS_ENV=production
CMD="bundle exec puma -C config/puma.rb"
cd /srv/servername/current
exec chpst -u "develop:develop" $CMD
# Check logrotate
logrotate
# Change config
sudo vi /etc/logrotate.conf
# Force run it
sudo logrotate -f /etc/logrotate.conf
Simple logrotate config
/srv/servername/current/log/puma.stdout.log {
size 100M
rotate 5
compress
delaycompress
missingok
notifempty
create 644 username username
}
https://www.digitalocean.com/community/tutorials/how-to-configure-a-redis-cluster-on-ubuntu-14-04
sudo add-apt-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install redis-server
# Check that Redis is up and running:
redis-benchmark -q -n 1000 -c 10 -P 5
sudo apt-get install imagemagick