Back to Deployment Guides

    Deploy Khoj AI on Your RamNode VPS

    Transform your VPS into a powerful AI-powered second brain with Khoj's advanced document search, chat capabilities, and automation features.

    30-45 min
    Setup Time
    4GB RAM
    Recommended
    Intermediate
    Difficulty
    Port 42110
    Default Port

    Why Choose Khoj AI?

    Khoj AI is an open-source, self-hostable AI assistant that acts as your "AI second brain," providing advanced features like document search, web integration, custom agents, and automation capabilities. Unlike cloud-hosted AI services, self-hosting provides unmatched privacy, customization, and control over your data.

    Advanced Document Processing

    Search your personal files and the internet with support for PDFs, Markdown, Word documents, and more to get accurate answers from your knowledge base.

    Universal AI Model Support

    Connect to various AI models including OpenAI GPT, Anthropic Claude, Google Gemini, and local models via Ollama for maximum flexibility.

    Custom AI Agents

    Create specialized agents tailored to your specific needs and workflows with personalized knowledge bases and tools.

    Cross-Platform Integration

    Use it through a web browser, desktop app, mobile, or integrate it with tools like Obsidian and WhatsApp.

    Prerequisites

    Recommended VPS Plan

    We recommend the 4GB Standard Cloud VPS plan for optimal Khoj AI performance:

    • 4GB RAM for smooth AI operations
    • 2+ CPU cores for better response times
    • 80GB+ SSD storage for documents and models
    • Sufficient bandwidth for API calls
    View Cloud VPS Plans

    Server Requirements

    • Ubuntu 20.04 LTS or newer
    • 4GB+ RAM (8GB recommended)
    • 20GB+ available storage
    • 2+ CPU cores

    Local Requirements

    • SSH client for server access
    • Basic command-line familiarity
    • Domain name (optional)
    • AI API keys (optional)

    Step 1: Initial Server Setup

    Connect and Update System

    Connect to your RamNode VPS via SSH and ensure the system is updated:

    # Connect to your VPS
    ssh root@your-vps-ip
    # Update system packages
    apt update && apt upgrade -y
    # Install essential tools
    apt install -y curl wget git htop nano ufw

    Configure Firewall

    # Enable UFW and configure basic rules
    ufw enable
    ufw default deny incoming
    ufw default allow outgoing
    ufw allow ssh
    ufw allow 42110/tcp # Khoj default port
    ufw status

    Step 2: Install Docker and Docker Compose

    Install Docker

    Docker provides better isolation and easier management for Khoj deployment

    # Add Docker's official GPG key
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    # Add Docker repository
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
    # Update package list and install Docker
    apt update
    apt install -y docker-ce docker-ce-cli containerd.io

    Install Docker Compose

    curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
    # Add current user to docker group (if not root)
    usermod -aG docker $USER

    Verify Installation

    docker --version
    docker-compose --version

    Step 3: Download and Configure Khoj

    Download Khoj Configuration

    # Create Khoj directory
    mkdir -p /opt/khoj && cd /opt/khoj
    # Download the official docker-compose.yml
    wget https://raw.githubusercontent.com/khoj-ai/khoj/master/docker-compose.yml
    # Create backup
    cp docker-compose.yml docker-compose.yml.backup

    Configure Environment Variables

    Edit the docker-compose.yml file to configure your Khoj instance

    nano docker-compose.yml

    Key configurations to modify:

    environment:
    # Required: Set secure admin credentials
    KHOJ_ADMIN_EMAIL: "your-email@domain.com"
    KHOJ_ADMIN_PASSWORD: "your-secure-password"
    KHOJ_DJANGO_SECRET_KEY: "your-very-long-secret-key-here"
    # Optional: External AI Model API Keys
    OPENAI_API_KEY: "sk-your-openai-key"
    ANTHROPIC_API_KEY: "sk-ant-your-anthropic-key"
    GEMINI_API_KEY: "your-gemini-key"
    # Security settings
    KHOJ_NO_HTTPS: "False"
    KHOJ_DOMAIN: "your-domain.com"

    Security Note

    Generate a strong secret key using:

    python3 -c "import secrets; print(secrets.token_urlsafe(50))"

    Step 4: Start Khoj Services

    Launch Khoj

    cd /opt/khoj
    docker-compose up -d

    Monitor the startup process:

    docker-compose logs -f

    Access Khoj

    Open your browser and navigate to:

    http://your-vps-ip:42110

    Admin panel access:

    http://your-vps-ip:42110/server/admin

    Step 5: Security Hardening

    Configure Nginx Reverse Proxy

    Set up Nginx with SSL for production deployments (recommended)

    Install Nginx and Certbot:

    apt install -y nginx certbot python3-certbot-nginx

    Create Nginx configuration:

    nano /etc/nginx/sites-available/khoj

    Add this configuration:

    server {
    listen 80;
    server_name your-domain.com;
    location / {
    proxy_pass http://127.0.0.1:42110;
    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;
    }
    }

    Enable site and get SSL certificate:

    ln -s /etc/nginx/sites-available/khoj /etc/nginx/sites-enabled/
    nginx -t && systemctl reload nginx
    # Get SSL certificate
    certbot --nginx -d your-domain.com
    # Update firewall
    ufw allow 'Nginx Full'
    ufw delete allow 42110/tcp # Remove direct access

    Configure Authentication

    By default, self-hosted Khoj runs in anonymous mode, but you can enable authentication with Magic Links or Google OAuth. For multi-user environments, configure authentication in the admin panel at /server/admin.

    Step 6: Document Integration and Sync

    Upload Documents

    Start using Khoj immediately by uploading documents through the web interface:

    1. Navigate to the web app at http://your-vps-ip:42110
    2. Use the drag-and-drop feature to upload PDFs, documents, and notes
    3. Khoj supports various file types including images, PDFs, Markdown, Word documents, and more

    Set Up Automated Sync (Optional)

    For continuous document sync, consider:

    • Desktop Client: Install the Khoj desktop app on your local machine
    • Obsidian Integration: Use the Khoj Obsidian plugin for seamless vault sync
    • API Integration: Set up custom scripts to sync documents programmatically

    Step 7: Performance Optimization

    Resource Monitoring

    # Check container resource usage
    docker stats
    # Monitor logs
    docker-compose logs -f --tail=100
    # Check disk usage
    df -h
    du -sh /opt/khoj/*

    Local AI Models (Advanced)

    For enhanced privacy and reduced API costs, set up local AI models with Ollama

    # Install Ollama
    curl -fsSL https://ollama.ai/install.sh | sh
    # Pull a model (example: Llama 3.2)
    ollama pull llama3.2
    # Start Ollama server
    ollama serve

    Update your docker-compose.yml to use local models by uncommenting the OPENAI_BASE_URL setting.

    Step 8: Maintenance and Updates

    Regular Updates

    cd /opt/khoj
    # Pull latest images
    docker-compose pull
    docker-compose up -d
    # Clean up old images
    docker system prune -a

    Backup Strategy

    # Backup configuration
    tar -czf khoj-config-$(date +%Y%m%d).tar.gz /opt/khoj/
    # Backup database
    pg_dump khoj > khoj-backup-$(date +%Y%m%d).sql

    Troubleshooting

    Memory Issues

    If Khoj errors out with "Killed" messages, increase RAM available to Docker containers. For VPS deployments, ensure you have adequate memory allocated (4GB minimum, 8GB recommended).

    Port Access Issues

    If you can't access Khoj remotely:

    # Check if port is listening
    netstat -tlnp | grep 42110
    # Verify firewall rules
    ufw status
    # Check Docker port mapping
    docker-compose ps

    SSL Certificate Issues

    For HTTPS access problems:

    # Check certificate status
    certbot certificates
    # Renew certificates
    certbot renew --nginx
    # Test SSL configuration
    nginx -t

    Frequently Asked Questions

    Ready to Deploy?

    Get started with RamNode's high-performance VPS hosting