VPS (Nginx)
This guide walks you through deploying WeaveAI to a VPS using Nginx as a reverse proxy and PM2 as a process manager.
Prerequisites
Section titled “Prerequisites”Before starting, ensure you have:
- A VPS running Ubuntu 22.04 LTS or Ubuntu 24.04 LTS
- Root/sudo and SSH access to your server
- A domain name pointed to your VPS IP address
Install Required Software
Section titled “Install Required Software”-
Connect to your VPS
Terminal window ssh root@your-server-ip -
Update system packages
Terminal window apt update -
Install Node.js v22 or v24
Terminal window # Download and install nvm:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash# in lieu of restarting the shell\. "$HOME/.nvm/nvm.sh"# Download and install Node.js v24:nvm install 24# Verify the Node.js version:node -v # Should print "v24.11.1".# Verify npm version:npm -v # Should print "11.6.2". -
Install PostgreSQL 17
Terminal window # Add PostgreSQL APT repositoryapt install -y postgresql-common/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y# Install PostgreSQL 17apt install -y postgresql-17 postgresql-contrib-17# Verify installationpsql --version # Should show PostgreSQL 17.x -
Install Nginx
Terminal window apt install -y nginx -
Install PM2 globally
Terminal window npm install -g pm2
Set Up PostgreSQL Database
Section titled “Set Up PostgreSQL Database”-
Switch to postgres user
Terminal window sudo -u postgres psql -
Create database and user
Run these commands in the PostgreSQL prompt:
CREATE DATABASE weaveai;CREATE USER weaveai_user WITH PASSWORD 'your_secure_password';GRANT ALL PRIVILEGES ON DATABASE weaveai TO weaveai_user;-- Connect to the weaveai database\c weaveai-- Grant schema privileges to your userGRANT ALL ON SCHEMA public TO weaveai_user;-- Make the user the owner of the database for full controlALTER DATABASE weaveai OWNER TO weaveai_user;\q -
Note your DATABASE_URL
Your
DATABASE_URLconnection string that goes in your .env file will be:postgresql://weaveai_user:your_secure_password@localhost:5432/weaveai
Deploy WeaveAI Application
Section titled “Deploy WeaveAI Application”-
Create application directory
Terminal window mkdir -p /var/www/weaveaicd /var/www/weaveai -
Upload your application files
You can either:
Option A: Using Git (if you’ve pushed to a private repository)
Terminal window git clone https://github.com/yourusername/your-repo.git .Option B: Using SCP from your local machine
Terminal window # Run this on your local machine (not the server)scp -r /path/to/weaveai/* root@your-server-ip:/var/www/weaveai/Option C: Using SFTP client (FileZilla, WinSCP, etc.)
-
Install Node.js Adapter
SvelteKit requires a deployment adapter for Node.js environments. Install the Node adapter:
Terminal window cd /var/www/weaveainpm install -D @sveltejs/adapter-nodeUpdate your
svelte.config.jsfile on the first line, changeadapter-autotoadapter-node:import adapter from "@sveltejs/adapter-auto"; // change this to @sveltejs/adapter-nodeimport { vitePreprocess } from "@sveltejs/vite-plugin-svelte";/** @type {import('@sveltejs/kit').Config} */const config = {preprocess: vitePreprocess(),kit: {adapter: adapter(),},};export default config; -
Install dependencies
Terminal window npm install -
Generate AUTH_SECRET
Before creating the environment file (
.env), generate your Auth.js secret using this Generator. -
Create environment file
Terminal window nano .envAdd your environment variables:
DATABASE_URL="postgresql://weaveai_user:your_secure_password@localhost:5432/weaveai"AUTH_SECRET="your_generated_auth_secret"PUBLIC_ORIGIN="https://your-domain.com"NODE_ENV="production"BODY_SIZE_LIMIT=104857600Save and exit (Ctrl+X, then Y, then Enter)
-
Build the application
Terminal window npm run build
Push Database Schema
Section titled “Push Database Schema”Before starting the application, you need to set up the database schema. Follow the Database Schema guide to push your schema using Drizzle.
Quick version:
cd /var/www/weaveainpm run db:pushConfigure PM2
Section titled “Configure PM2”-
Start the application with PM2
Terminal window cd /var/www/weaveaipm2 start build/index.js --name "weaveai" --node-args="--env-file=.env" -
Configure PM2 to start on boot
Terminal window pm2 startuppm2 save -
Verify the application is running
Terminal window pm2 statuspm2 logs weaveaiThe application should now be running on
http://localhost:3000
Configure Nginx
Section titled “Configure Nginx”-
Create Nginx configuration
Terminal window nano /etc/nginx/sites-available/weaveaiAdd the following configuration:
server {listen 80;server_name your-domain.com www.your-domain.com;location / {proxy_pass http://localhost:3000;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection 'upgrade';proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;proxy_cache_bypass $http_upgrade;proxy_buffer_size 256k;proxy_buffers 4 512k;proxy_busy_buffers_size 512k;}}Replace
your-domain.comwith your actual domain.Save and exit (Ctrl+X, then Y, then Enter)
-
Enable the site
Terminal window ln -s /etc/nginx/sites-available/weaveai /etc/nginx/sites-enabled/ -
Test Nginx configuration
Terminal window nginx -t -
Restart Nginx
Terminal window systemctl restart nginx
Set Up SSL
Section titled “Set Up SSL”-
Install Certbot
Terminal window apt install -y certbot python3-certbot-nginx -
Obtain SSL certificate
Terminal window certbot --nginx -d your-domain.com -d www.your-domain.comFollow the prompts to complete the SSL setup.
-
Auto-renewal is configured automatically
Test renewal:
Terminal window certbot renew --dry-run
Verify Deployment
Section titled “Verify Deployment”-
Check application status
Terminal window pm2 statuspm2 logs weaveai -
Check Nginx status
Terminal window systemctl status nginx -
Visit your application - Open your browser and navigate to your domain
Useful PM2 Commands
Section titled “Useful PM2 Commands”- View logs:
pm2 logs weaveai - Restart app:
pm2 restart weaveai - Stop app:
pm2 stop weaveai - Delete app from PM2:
pm2 delete weaveai - Monitor resources:
pm2 monit
Updating WeaveAI
Section titled “Updating WeaveAI”When a new version is available:
-
Stop the application
Terminal window pm2 stop weaveai -
Backup your .env file
Terminal window cp /var/www/weaveai/.env /var/www/weaveai/.env.backup -
Update the application files
If using Git:
Terminal window cd /var/www/weaveaigit pullIf uploading manually, upload the new files via SCP or SFTP
-
Install any new dependencies
Terminal window npm install -
Rebuild the application
Terminal window npm run build -
Push database schema if needed
Terminal window npm run db:push -
Restart the application
Terminal window pm2 restart weaveai -
Verify everything works
Terminal window pm2 logs weaveai