Skip to content

Instantly share code, notes, and snippets.

@martinblaha
Forked from jtadeulopes/server.md
Last active September 7, 2020 15:49
Show Gist options
  • Save martinblaha/181186e8ad9a2d56047a9f86ee4ba972 to your computer and use it in GitHub Desktop.
Save martinblaha/181186e8ad9a2d56047a9f86ee4ba972 to your computer and use it in GitHub Desktop.
Server setup with debian 9 nginx and puma for rails app.

Update and upgrade the system

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade && sudo apt-get autoremove
sudo reboot

Configure timezone

sudo dpkg-reconfigure tzdata
sudo apt-get install -y ntp
sudo ntpd ntp.ubuntu.com
date

Create new user

sudo adduser manager
sudo adduser manager sudo

Edit /etc/sudoers

%sudo ALL=(ALL:ALL) ALL
manager ALL=NOPASSWD: ALL

Environment variables

Edit /etc/profile

export RAILS_ENV=production

Edit /etc/environment

RAILS_ENV=production

Some libraries for Mysql, ImageMagick, etc

sudo apt-get install -y libmagickwand-dev default-libmysqlclient-dev imagemagick libpq-dev htop curl
sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt install nodejs
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable --ruby

sudo apt-get install -y libyaml-dev libssl-dev libreadline-dev libxml2-dev libxslt1-dev libffi-dev build-essential

Compiled:

wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.4.tar.gz
tar xvfz ruby-2.1.4.tar.gz
cd ruby-2.1.4/
./configure --prefix=/opt/ruby --disable-install-rdoc
make
sudo make install
sudo gem install bundler

GIT

sudo apt-get install -y git

VIM

Global settings

Edit /etc/vim/vimrc and add the lines below

set number
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

OpenSSL

sudo apt-get install openssl

Nginx

sudo apt install nginx
# or install following: https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#prebuilt_debian

Nginx settings

cd /opt/nginx/conf
sudo rm nginx.conf
Download the file https://gist.github.com/jtadeulopes/7237669

cd /etc/nginx/sites-enabled

Download the file https://gist.github.com/jtadeulopes/7237731
Or with SSL support https://gist.github.com/jtadeulopes/9189120

Upstart script

cd /etc/init
Download the file https://gist.github.com/jtadeulopes/7237115

Now, you can run:

sudo (start|restart|stop) nginx

Deploy

Add user

sudo adduser deploy

SSH keys

sudo -iu deploy
ssh-keygen -t rsa

Add authorized keys

cd
vim .ssh/authorized_keys

Copy and paste public keys
exit

Create folder to deploy the app

sudo mkdir /var/www
sudo chown deploy:deploy -c -R /var/www

Capistrano

Capfile https://gist.github.com/jtadeulopes/7249948

deploy.rb https://gist.github.com/jtadeulopes/7249921

Puma Upstart script

For each project, you must create the puma upstart file

cd /etc/init
Download the file https://gist.github.com/jtadeulopes/7254953

With the upstart for each project, you can run:

sudo (start|restart|stop) project

Puma config

cd my/project/path/config
Download the file https://gist.github.com/jtadeulopes/7265503

Monit

sudo apt-get install -y monit

For each project, you must create the monit confg file

cd /etc/monit/conf.d
Download the file https://gist.github.com/jtadeulopes/7270279

Edit /etc/monit/monitrc

set daemon 60

Restart monit

sudo /etc/init.d/monit restart

Bower

sudo ln -s /usr/bin/nodejs /usr/bin/node
sudo npm install -g bower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment