-
Notifications
You must be signed in to change notification settings - Fork 9
/
SetUpServer.txt
183 lines (143 loc) · 5.21 KB
/
SetUpServer.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# set up user
ssh root@yourserverip
adduser deploy
adduser deploy sudo
vi /etc/ssh/sshd_config
enable PasswordAuthentication
save
systemctl restart sshd
exit
ssh-copy-id deploy@yourserverip
# log in
ssh deploy@yourserverip
# basic packages
# Adding Node.js repository
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
# Adding Yarn repository
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo add-apt-repository ppa:chris-lea/redis-server
# Refresh our packages list with the new repositories
sudo apt-get update
# Install our dependencies for compiiling Ruby along with Node.js and Yarn
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 software-properties-common libffi-dev dirmngr gnupg apt-transport-https ca-certificates redis-server redis-tools nodejs yarn
#install ruby
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
git clone https://github.com/rbenv/rbenv-vars.git ~/.rbenv/plugins/rbenv-vars
exec $SHELL
rbenv install 2.7.2
rbenv global 2.7.2
ruby -v
# ruby 2.7.2
# This installs the latest Bundler, currently 2.x.
gem install bundler
bundle -v
sudo apt update && sudo apt -y upgrade && sudo apt-get autoclean && sudo apt-get -y autoremove
# nginx/passenger
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger focal main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
sudo apt-get install -y nginx-extras libnginx-mod-http-passenger
if [ ! -f /etc/nginx/modules-enabled/50-mod-http-passenger.conf ]; then sudo ln -s /usr/share/nginx/modules-available/mod-http-passenger.load /etc/nginx/modules-enabled/50-mod-http-passenger.conf ; fi
sudo ls /etc/nginx/conf.d/mod-http-passenger.conf
sudo vim /etc/nginx/conf.d/mod-http-passenger.conf
# add line
passenger_ruby /home/deploy/.rbenv/shims/ruby;
sudo service nginx start
sudo rm /etc/nginx/sites-enabled/default
# install ufw
sudo ufw default allow outgoing
sudo ufw allow 'Nginx Full'
sudo ufw allow OpenSSH
sudo vim /etc/nginx/sites-enabled/yourapp
# basic for port 80
server {
listen 80 ;
listen [::]:80;
server_name www.yourdomain yourdomain;
return 301 https://yourdomain$request_uri;
}
# install certbot
sudo apt install certbot python3-certbot-nginx
sudo certbot certonly --nginx
sudo vim /etc/nginx/sites-enabled/yourapp-ssl
# /etc/nginx/sites-enabled/yourapp-ssl
server {
listen 443 ssl;
server_name yourdomain;
# ssl_certificate /etc/letsencrypt/live/yourdomain/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/yourdomain/privkey.pem;
root /home/deploy/yourapp/current/public;
passenger_enabled on;
passenger_app_env production;
access_log /var/log/nginx/app.access.log;
error_log /var/log/nginx/app.error.log;
location /cable {
passenger_app_group_name yourapp_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
# Allow uploads up to 100MB in size
client_max_body_size 100m;
location ~ ^/(assets|packs) {
expires max;
gzip_static on;
}
# this rewrites all the requests to the maintenance.html
# page if it exists in the doc root. This is for capistrano's
# disable web task
if (-f $document_root/system/maintenance.html)
{
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
}
sudo service nginx reload
##### CREATE DATABASE #####
## best to do managed, but for now local ##
sudo apt-get install postgresql postgresql-contrib libpq-dev
sudo su - postgres
createuser --pwprompt deploy
createdb -O deploy yourapp
exit
vi /home/deploy/yourapp/.rbenv-vars
# .rbenv-vars
# For Postgres
DATABASE_URL=postgresql://deploy:[email protected]/yourapp
SECRET_KEY_BASE=ASECRET
# alter gem file to add pg
gem 'pg', '>= 0.18', '< 2.0'
#move mysql to dev test
# capistrano
# gemfile
gem 'capistrano', '~> 3.11'
gem 'capistrano-rails', '~> 1.4'
gem 'capistrano-passenger', '~> 0.2.0'
gem 'capistrano-rbenv', '~> 2.1', '>= 2.1.4'
bundle
cap install STAGES=production
# edit Capfile
require 'capistrano/rails'
require 'capistrano/passenger'
require 'capistrano/rbenv'
set :rbenv_type, :user
set :rbenv_ruby, '2.7.2' # or whatever version you chose
# config/deploy.rb
set :application, "yourapp"
set :repo_url, "[email protected]:philsmy/cable-guy-example.git"
set :branch, 'main'
# Deploy to the user's home directory
set :deploy_to, "/home/deploy/#{fetch :application}"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
# Only keep the last 5 releases to save disk space
set :keep_releases, 5
# config/deploy/production
server 'yourserverip', user: 'deploy', roles: %w{app db web}
cap production deploy
# add console file
export RAILS_ENV=production
cd /home/deploy/yourapp/current
bundle exec rails c