Deployment Guide (Hostinger VPS)
Target
Deploy the Next.js app with PostgreSQL, serving HTTPS traffic via Nginx.
Prerequisites
- Hostinger VPS with Ubuntu 22.04+
- Domain pointed to VPS IP
- Node.js 20+
- PostgreSQL 15+
- Nginx
- PM2
1. Install Base Packages
sudo apt update
sudo apt install -y curl git build-essential nginx postgresql postgresql-contrib
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm install -g pm2
2. Prepare App Directory
cd /var/www
sudo mkdir -p whatidotoday
sudo chown -R $USER:$USER whatidotoday
cd whatidotoday
Copy project files into this folder (git clone or rsync/scp).
3. Configure Environment
Create .env in project root:
DATABASE_URL="postgresql://<db_user>:<db_pass>@localhost:5432/what_i_do_today?schema=public"
AUTH_SECRET="<long-random-secret>"
APP_TIME_ZONE="Asia/Kuala_Lumpur"
NODE_ENV="production"
OPENAI_API_KEY=""
OPENAI_MODEL="gpt-4.1-mini"
Generate strong secret example:
openssl rand -base64 48
4. Setup PostgreSQL
sudo -u postgres psql
Inside psql:
CREATE DATABASE what_i_do_today;
CREATE USER widt_user WITH ENCRYPTED PASSWORD '<strong-password>';
GRANT ALL PRIVILEGES ON DATABASE what_i_do_today TO widt_user;
\q
5. Install and Build
cd /var/www/whatidotoday
npm install
npm run prisma:generate
npm run prisma:migrate
npm test
npm run build
6. Run with PM2
cd /var/www/whatidotoday
pm2 start npm --name "whatidotoday" -- start
pm2 save
pm2 startup
Check status:
pm2 status
pm2 logs whatidotoday --lines 100
6.1 Configure Scheduled Export Cron
crontab -e
Add:
0 * * * * cd /var/www/whatidotoday && npm run cron:exports >> /var/log/widt-cron.log 2>&1
7. Configure Nginx Reverse Proxy
Create /etc/nginx/sites-available/whatidotoday:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable config:
sudo ln -s /etc/nginx/sites-available/whatidotoday /etc/nginx/sites-enabled/whatidotoday
sudo nginx -t
sudo systemctl reload nginx
8. Enable HTTPS
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
9. Update Workflow
cd /var/www/whatidotoday
git pull
npm install
npm run prisma:migrate
npm test
npm run build
pm2 restart whatidotoday
10. Smoke Check
- Open
https://yourdomain.com/setup - Create admin account once
- Login and add a test log
- Verify CSV/PDF export
- Verify analytics/team pages
- Create one scheduled export and run
npm run cron:exports