Skip to content

Commit c48765f

Browse files
task(#vps-how-to): add vps how to helper file
1 parent 4e44003 commit c48765f

2 files changed

Lines changed: 176 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Deploy to VPS Server
33
on:
44
release:
55
types: [created]
6+
workflow_dispatch:
67

78
jobs:
89
lint:

VPS_SETUP.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# VPS Setup Guide
2+
3+
## Prerequisites
4+
5+
- Ubuntu/Debian VPS
6+
- Domain DNS A records pointing to VPS IP
7+
- Hosting provider must allow your domain (e.g. register `rnstudio.hu` in their panel)
8+
9+
## 1. Install Git
10+
11+
```bash
12+
sudo apt-get update
13+
sudo apt-get install -y git
14+
git --version
15+
```
16+
17+
## 2. Install Node.js 20
18+
19+
```bash
20+
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -
21+
sudo apt-get install -y nodejs
22+
node -v
23+
```
24+
25+
## 3. Install Yarn
26+
27+
```bash
28+
corepack enable
29+
corepack prepare yarn@stable --activate
30+
yarn -v
31+
```
32+
33+
## 4. Install PM2
34+
35+
```bash
36+
npm install -g pm2
37+
pm2 -v
38+
```
39+
40+
## 5. Add Swap (needed for VPS with ≤1GB RAM)
41+
42+
```bash
43+
sudo fallocate -l 2G /swapfile
44+
sudo chmod 600 /swapfile
45+
sudo mkswap /swapfile
46+
sudo swapon /swapfile
47+
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
48+
free -h
49+
```
50+
51+
## 6. Clone the Repo
52+
53+
```bash
54+
cd ~
55+
git clone <your-repo-url> rnstudio.hu
56+
cd rnstudio.hu
57+
```
58+
59+
## 7. Create Environment File
60+
61+
```bash
62+
cp .env.sample .env.local
63+
nano .env.local
64+
```
65+
66+
Set these values:
67+
68+
```
69+
G_USER=<your-github-username>
70+
G_TOKEN=<your-github-personal-access-token>
71+
```
72+
73+
Save: `Ctrl+O`, `Enter`, `Ctrl+X`
74+
75+
## 8. Install Dependencies and Build
76+
77+
```bash
78+
yarn install
79+
yarn build
80+
```
81+
82+
## 9. Start with PM2
83+
84+
```bash
85+
pm2 start yarn --name "nextjs-app" -- start
86+
pm2 save
87+
pm2 startup
88+
```
89+
90+
`pm2 startup` prints a `sudo` command — copy and run it so the app auto-starts after reboot.
91+
92+
Verify: `pm2 status` should show `nextjs-app` as `online`.
93+
94+
## 10. Install and Configure Nginx
95+
96+
```bash
97+
sudo apt-get install -y nginx
98+
sudo rm -f /etc/nginx/sites-enabled/default
99+
```
100+
101+
Create the site config:
102+
103+
```bash
104+
sudo tee /etc/nginx/sites-available/rnstudio.hu > /dev/null << 'EOF'
105+
server {
106+
listen 80 default_server;
107+
listen [::]:80 default_server;
108+
server_name rnstudio.hu www.rnstudio.hu;
109+
110+
location / {
111+
proxy_pass http://localhost:3000;
112+
proxy_set_header Host $host;
113+
proxy_set_header X-Real-IP $remote_addr;
114+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
115+
proxy_set_header X-Forwarded-Proto $scheme;
116+
}
117+
}
118+
EOF
119+
```
120+
121+
Enable and restart:
122+
123+
```bash
124+
sudo ln -s /etc/nginx/sites-available/rnstudio.hu /etc/nginx/sites-enabled/
125+
sudo nginx -t
126+
sudo systemctl restart nginx
127+
```
128+
129+
## 11. Set Up SSL with Let's Encrypt
130+
131+
```bash
132+
sudo apt-get install -y certbot python3-certbot-nginx
133+
sudo certbot --nginx -d rnstudio.hu -d www.rnstudio.hu
134+
sudo certbot renew --dry-run
135+
```
136+
137+
## 12. Add SSH Key for CI/CD
138+
139+
```bash
140+
mkdir -p ~/.ssh
141+
chmod 700 ~/.ssh
142+
nano ~/.ssh/authorized_keys
143+
```
144+
145+
Paste the public key matching the `SSH_PRIVATE_KEY` GitHub secret, then save.
146+
147+
```bash
148+
chmod 600 ~/.ssh/authorized_keys
149+
```
150+
151+
## GitHub Secrets Required
152+
153+
| Secret | Value |
154+
| ---------------- | ---------------------------------- |
155+
| `G_USER` | GitHub username |
156+
| `G_TOKEN` | GitHub personal access token |
157+
| `SSH_PRIVATE_KEY` | Private SSH key for VPS access |
158+
| `SSH_VPS_IP` | VPS IP address |
159+
| `SSH_USER` | SSH username on the VPS |
160+
| `ACTIONS_PAT` | PAT for auto version bump pushes |
161+
162+
## Manual Deploy (without CI)
163+
164+
```bash
165+
ssh user@your-vps
166+
cd rnstudio.hu
167+
git pull origin main
168+
yarn install
169+
yarn build
170+
pm2 restart nextjs-app
171+
```
172+
173+
## Automated Deploy
174+
175+
Creating a GitHub Release triggers the deploy workflow, which SSHes into the VPS and runs pull/install/build/restart automatically.

0 commit comments

Comments
 (0)