Eric Guo's

in HTML5, JavaScript, Ruby & Rails, Python, and Cloud MES!

Deploy New Rails 6 Application in Ubuntu 20.04


Create new user

adduser cybros_vendor
sudo su - cybros_vendor
mkdir .ssh
chmod 700 .ssh
vi .ssh/authorized_keys # and paste your public key
chmod 600 .ssh/authorized_keys

Enable new user as sudo

sudo su -
cd /etc/sudoers.d/
echo "cybros_vendor ALL=(ALL) NOPASSWD:ALL" > 80-cybros_vendor-user

Install nginx

sudo apt-get install nginx

It’s also possible to enable TLS 1.1/1.2 due to Ubuntu 20.04 not support by default.

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
# seclevel for TLS 1.0 and 1.1

Install node.js 15 and yarn 1.x

Using nodesource distribution

curl -fsSL | sudo -E bash -
sudo apt-get install gcc g++ make git
sudo apt-get install -y nodejs
## To install the Yarn package manager
curl -sL | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

Install rbenv and Ruby 3.0.1

sudo apt install rbenv
sudo su - cybros_vendor
mkdir -p "$(rbenv root)"/plugins
git clone "$(rbenv root)"/plugins/ruby-build
git clone "$(rbenv root)"/plugins/rbenv-china-mirror
rbenv install 3.0.1
rbenv global 3.0.1
echo "gem: --no-document" > ~/.gemrc
eval "$(rbenv init -)" >> ~/.bash_profile # or past the `rbenv init -`
rbenv shell 3.0.1

Install MySQL Client

sudo apt-get install gnupg2
wget$(lsb_release -sc)_all.deb
sudo dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb
sudo percona-release setup ps80
sudo apt-get install percona-server-client
sudo apt-get install libmysqlclient-dev

Create MySQL DB user

mysql -u root -p
CREATE DATABASE cybros_vendor character set UTF8mb4 collate utf8mb4_bin;
CREATE USER 'cybros_vendor'@'%' IDENTIFIED BY 'cybros_vendor_password';
GRANT ALL ON cybros_vendor.* TO 'cybros_vendor'@'%';

Link rbenv to make capistrano works

mkdir -p ~/.rbenv/bin
cd ~/.rbenv/bin
ln -s /usr/bin/rbenv rbenv

Install Oracle Instant Client

Download Version and following ruby-oci8 document

sudo mkdir /opt/oracle
sudo unzip -d /opt/oracle
sudo unzip -d /opt/oracle/
sudo unzip -d /opt/oracle/
cd /usr/local/bin
sudo ln -s /opt/oracle/instantclient_19_11/sqlplus sqlplus
export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_11
gem install ruby-oci8
Append tolink

Also need setting in systemd/system/puma_service or side_service