Skip to content

Instantly share code, notes, and snippets.

@abelorian
Last active January 25, 2021 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelorian/6e4ccc37e0ae78f66447de979fc7f314 to your computer and use it in GitHub Desktop.
Save abelorian/6e4ccc37e0ae78f66447de979fc7f314 to your computer and use it in GitHub Desktop.
My ubuntu 18.04 server

Droplet

Create a new, start with the smallest droplet. Use Ubuntu 20.04, log in as root.

Server

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install build-essential git-core curl zlib1g-dev libssl-dev libreadline-dev libmysqlclient-dev nginx -y
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install nodejs -y

1. Create non-root user 'deploy'

create user 'deploy'

adduser deploy

Add to sudoers group

usermod -aG sudo deploy

Switch user to 'deploy'

su - deploy

Create ssh key

ssh-keygen

Create sym link for webroot

cd ~
ln -s /var/www/html html

sudo visudo

deploy ALL=(ALL) NOPASSWD:ALL

nano /etc/ssh/sshd_config

PasswordAuthenticacion Yes

sudo service ssh restart

2. Swapfile

Check swapfile

free -h

Check freespace

df -h

Create a 4gb Swap File

sudo fallocate -l 4G /swapfile

Verify

ls -lh /swapfile

Lock it down

sudo chmod 600 /swapfile

Make it swap

sudo mkswap /swapfile

Enable it

sudo swapon /swapfile

Verify

sudo swapon --show

Check swapfile

free -h

Make it permanent

sudo cp /etc/fstab /etc/fstab.bak;
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

3. NGINX

How To Install Nginx on Ubuntu 16.04

Install NGINX

sudo apt-get update
sudo apt-get install nginx

Check status

systemctl status nginx

Tweak UFW firewall

sudo ufw allow 'OpenSSH'
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status

Install CURL, get your IP, and check that you can request a page in your browser!

sudo apt-get install curl
curl -4 icanhazip.com

Actions*

sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx

5.1 Rbenv

https://github.com/rbenv/rbenv#basic-github-checkout

mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

5.2 Ruby

rbenv install 2.6.3
rbenv global 2.6.3

gem install bundler -v 1.17.2
gem install rake

6. Rails

Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma

Install Rails and bundler

gem install rails -v '5.2.3'
gem install bundler

Authorize your server to read from your repo, you'll have to add a deployment key to your repo. To do this you must copy your ~/.ssh/id_rsa.pub file to your repo (make sure this is your deployment user, eg. rails)

Secret_base_key:

subir master.key a shared en el server

rake secret

EDITOR='subl --wait' rails credentials:edit

https://stackoverflow.com/questions/51466887/rails-how-to-fix-missing-secret-key-base-for-production-environment

7 Capistrano

gem 'capistrano', '3.11.2' gem 'capistrano-rbenv', '2.1.4' gem 'capistrano-rails', '1.4.0' gem 'capistrano3-puma', require: false

mysql

systemctl status mysql.service

https://www.digitalocean.com/community/tutorials/how-to-install-the-latest-mysql-on-ubuntu-18-04

sudo mysql_secure_installation

sudo mysql -u root

apt-key adv --keyserver keys.gnupg.net --recv-keys 8C718D3B5072E1F5 apt-get install libmysqlclient-dev

https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost

Authorized keys

Add your local key to the server, if this doesn't work just add your local public key (id_rsa.pub) to /home/deploy/.ssh/authorized_keys

ssh-rsa ... ssh-rsa ...

Deploy

  • Update rsa keys

  • Replace IP in deploy file

  • Update nginx site config

  • Active puma service on boot

SSL for HTTPS

  • certbot Let's Encrypt

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-20-04-es

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