Skip to content

VPS (Nginx)

This guide walks you through deploying WeaveAI to a VPS using Nginx as a reverse proxy and PM2 as a process manager.

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
  1. Connect to your VPS

    Terminal window
    ssh root@your-server-ip
  2. Update system packages

    Terminal window
    apt update
  3. 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".
  4. Install PostgreSQL 17

    Terminal window
    # Add PostgreSQL APT repository
    apt install -y postgresql-common
    /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
    # Install PostgreSQL 17
    apt install -y postgresql-17 postgresql-contrib-17
    # Verify installation
    psql --version # Should show PostgreSQL 17.x
  5. Install Nginx

    Terminal window
    apt install -y nginx
  6. Install PM2 globally

    Terminal window
    npm install -g pm2
  1. Switch to postgres user

    Terminal window
    sudo -u postgres psql
  2. 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 user
    GRANT ALL ON SCHEMA public TO weaveai_user;
    -- Make the user the owner of the database for full control
    ALTER DATABASE weaveai OWNER TO weaveai_user;
    \q
  3. Note your DATABASE_URL

    Your DATABASE_URL connection string that goes in your .env file will be:

    postgresql://weaveai_user:your_secure_password@localhost:5432/weaveai
  1. Create application directory

    Terminal window
    mkdir -p /var/www/weaveai
    cd /var/www/weaveai
  2. 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.)

  3. Install Node.js Adapter

    SvelteKit requires a deployment adapter for Node.js environments. Install the Node adapter:

    Terminal window
    cd /var/www/weaveai
    npm install -D @sveltejs/adapter-node

    Update your svelte.config.js file on the first line, change adapter-auto to adapter-node:

    import adapter from "@sveltejs/adapter-auto"; // change this to @sveltejs/adapter-node
    import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
    /** @type {import('@sveltejs/kit').Config} */
    const config = {
    preprocess: vitePreprocess(),
    kit: {
    adapter: adapter(),
    },
    };
    export default config;
  4. Install dependencies

    Terminal window
    npm install
  5. Generate AUTH_SECRET

    Before creating the environment file (.env), generate your Auth.js secret using this Generator.

  6. Create environment file

    Terminal window
    nano .env

    Add 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=104857600

    Save and exit (Ctrl+X, then Y, then Enter)

  7. Build the application

    Terminal window
    npm run build

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:

Terminal window
cd /var/www/weaveai
npm run db:push
  1. Start the application with PM2

    Terminal window
    cd /var/www/weaveai
    pm2 start build/index.js --name "weaveai" --node-args="--env-file=.env"
  2. Configure PM2 to start on boot

    Terminal window
    pm2 startup
    pm2 save
  3. Verify the application is running

    Terminal window
    pm2 status
    pm2 logs weaveai

    The application should now be running on http://localhost:3000

  1. Create Nginx configuration

    Terminal window
    nano /etc/nginx/sites-available/weaveai

    Add 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.com with your actual domain.

    Save and exit (Ctrl+X, then Y, then Enter)

  2. Enable the site

    Terminal window
    ln -s /etc/nginx/sites-available/weaveai /etc/nginx/sites-enabled/
  3. Test Nginx configuration

    Terminal window
    nginx -t
  4. Restart Nginx

    Terminal window
    systemctl restart nginx
  1. Install Certbot

    Terminal window
    apt install -y certbot python3-certbot-nginx
  2. Obtain SSL certificate

    Terminal window
    certbot --nginx -d your-domain.com -d www.your-domain.com

    Follow the prompts to complete the SSL setup.

  3. Auto-renewal is configured automatically

    Test renewal:

    Terminal window
    certbot renew --dry-run
  1. Check application status

    Terminal window
    pm2 status
    pm2 logs weaveai
  2. Check Nginx status

    Terminal window
    systemctl status nginx
  3. Visit your application - Open your browser and navigate to your domain

  • 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

When a new version is available:

  1. Stop the application

    Terminal window
    pm2 stop weaveai
  2. Backup your .env file

    Terminal window
    cp /var/www/weaveai/.env /var/www/weaveai/.env.backup
  3. Update the application files

    If using Git:

    Terminal window
    cd /var/www/weaveai
    git pull

    If uploading manually, upload the new files via SCP or SFTP

  4. Install any new dependencies

    Terminal window
    npm install
  5. Rebuild the application

    Terminal window
    npm run build
  6. Push database schema if needed

    Terminal window
    npm run db:push
  7. Restart the application

    Terminal window
    pm2 restart weaveai
  8. Verify everything works

    Terminal window
    pm2 logs weaveai