Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

Self-Host LLMs with Ollama and Open WebUI

By Kokil Thapa | Last reviewed: August 2026

You want to run large language models locally but need a practical path that avoids cloud API costs and keeps proprietary data off third-party servers. Learning to self-host LLMs with Ollama and Open WebUI gives you a private, production-grade inference stack on your own hardware. This guide covers the exact installation, configuration, and operational patterns I use when deploying local AI infrastructure for development workflows and internal business tools.

Before diving into terminal commands, understand that this stack replaces two separate concerns: the inference engine (Ollama) and the user interface (Open WebUI). For teams evaluating whether to build custom AI tooling versus buying SaaS, understanding the technical trade-offs between custom and managed solutions helps frame the investment in local hardware correctly. Self-hosting makes sense when data privacy, latency, or recurring API costs outweigh the operational overhead of maintaining your own GPU server.

How do you install and configure Ollama for local model serving?

Ollama is the backend runtime that downloads, caches, and serves quantized GGUF models through a REST API. On Ubuntu 24.04 LTS, the official install script handles binary placement and systemd unit creation automatically. Run the installer with curl, then verify the service is active before pulling any models.

curl -fsSL https://ollama.com/install.sh | sh
sudo systemctl enable --now ollama
systemctl status ollama

The default installation binds to localhost:11434. For multi-user environments or when Open WebUI runs in a separate Docker network, you must explicitly bind to all interfaces and configure environment variables for GPU selection and concurrent request handling. Edit the systemd override file rather than modifying the vendor unit directly, so package upgrades do not clobber your changes.

sudo systemctl edit ollama

# Add to the [Service] section:
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Environment="OLLAMA_NUM_PARALLEL=4"
Environment="CUDA_VISIBLE_DEVICES=0"
Environment="OLLAMA_MAX_LOADED_MODELS=2"

After saving the override, reload the daemon and restart the service. The OLLAMA_NUM_PARALLEL variable controls how many requests a single loaded model can handle simultaneously; setting this too high on limited VRAM causes silent failures where requests queue indefinitely. Start with 2–4 for consumer GPUs and test under realistic load. The OLLAMA_MAX_LOADED_MODELS parameter prevents memory exhaustion when users switch between models frequently; each loaded model reserves its full context window in VRAM regardless of active usage.

Systemd Serviceollama.serviceAuto-restart + loggingModel Storage~/.ollama/modelsGGUF quantized weightsREST API0.0.0.0:11434/api/chat /api/generateGPU Memory PoolVRAM reserved per loaded modelContext window × batch size
Ollama component architecture: systemd manages the process, models persist on disk, the REST API exposes inference endpoints, and GPU memory is allocated per loaded model context window.

Pull a baseline model to validate the installation end-to-end. Llama 3.1 8B Instruct at Q4_K_M quantization offers the best balance of quality and VRAM footprint for most development tasks. The pull command streams progress to stdout; subsequent loads skip download if the digest matches.

ollama pull llama3.1:8b-instruct-q4_K_M
ollama list
curl http://localhost:11434/api/tags

What is the correct Docker Compose configuration for Open WebUI?

Open WebUI provides the chat interface, RAG pipeline, user management, and model administration layer that sits in front of Ollama. Running it in Docker isolates Node.js and Python dependencies from your host system and simplifies upgrades. The critical configuration details are the volume mount for persistent data, the correct Ollama base URL (which differs inside Docker networking), and GPU device reservation if you plan to use Open WebUI's built-in embedding models.

version: '3.8'
services:
  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: open-webui
    restart: unless-stopped
    ports:
      - "3000:8080"
    volumes:
      - open-webui-data:/app/backend/data
    environment:
      - OLLAMA_BASE_URL=http://host.docker.internal:11434
      - WEBUI_AUTH=true
      - ENABLE_SIGNUP=false
      - DEFAULT_USER_ROLE=admin
    extra_hosts:
      - "host.docker.internal:host-gateway"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

volumes:
  open-webui-data:

The host.docker.internal hostname resolves to the Docker host from inside the container, but only when you include the extra_hosts directive. Without it, Open WebUI cannot reach Ollama bound to localhost. On Linux systems where this alias fails, replace it with the host's LAN IP or use a custom Docker network with explicit service linking. The named volume open-webui-data stores SQLite databases, uploaded files, RAG vector indices, and user settings; losing this volume means losing all chat history and configured knowledge bases.

Set WEBUI_AUTH=true and ENABLE_SIGNUP=false for any deployment beyond personal use. The first account created becomes the administrator; subsequent users require admin invitation. Disabling open signup prevents unauthorized access on shared networks. For teams managing multiple client projects, understanding current security practices for web applications ensures your local AI instance does not become an unmonitored attack surface.

How does GPU acceleration affect inference performance and model selection?

Running LLMs on CPU alone produces 1–3 tokens per second for 8B parameter models, which is unusable for interactive chat. NVIDIA GPU acceleration via CUDA is effectively mandatory for any real workload. The relationship between VRAM capacity, model quantization, and context length determines what you can actually run without swapping to system RAM, which collapses performance back to CPU speeds.

GPU ModelVRAMMax Comfortable ModelContext Limit (Q4_K_M)Approx. Tokens/sec
RTX 3060 12GB12 GBLlama 3.1 8B Q4_K_M8K35–45
RTX 4070 Ti Super16 GBMistral-Nemo 12B Q5_K_M16K55–70
RTX 409024 GBQwen2.5 32B Q4_K_M16K60–80
A100 80GB80 GBLlama 3.1 70B Q4_K_M32K+40–55

These numbers assume the entire model fits in VRAM with headroom for KV cache. When VRAM fills, Ollama silently offloads layers to CPU, and throughput drops non-linearly. Monitor actual GPU memory usage during inference with nvidia-smi -l 1 rather than trusting theoretical calculations. Context length consumes VRAM quadratically for some attention implementations; doubling context can consume far more than double the memory.

Check Available VRAM< 12 GB VRAM?YesNoUse Q3_K_M or Q4_07B models onlyUse Q4_K_M or Q5_K_MUp to 32B modelsTest + monitor nvidia-smiTest + monitor nvidia-smi
Model quantization decision tree: match your GPU VRAM to appropriate quantization levels to avoid silent CPU offloading that destroys inference speed.

For teams without dedicated GPU hardware, consider renting cloud GPU instances temporarily for evaluation before purchasing. A single RTX 4090 workstation in Nepal costs roughly NPR 350,000–450,000 (~USD 2,600–3,300) including PSU and cooling upgrades, while equivalent cloud rental runs USD 0.40–0.80/hour. Break-even for continuous use hits around 4–6 months. If your usage is sporadic or experimental, cloud rental remains cheaper. For businesses evaluating infrastructure investments, comparing local hosting providers and pricing against owned hardware clarifies the true total cost.

How do you implement RAG and document ingestion securely?

Open WebUI includes a built-in RAG pipeline using sentence-transformers embeddings stored in ChromaDB by default. Upload PDFs, markdown files, or plain text through the workspace interface, and the system chunks, embeds, and indexes them automatically. However, the default embedding model (all-MiniLM-L6-v2) produces mediocre retrieval quality for domain-specific content. Replace it with bge-m3 or nomic-embed-text for significantly better recall on technical documentation and legal texts.

# Inside Open WebUI Admin Settings → RAG
Embedding Model: nomic-ai/nomic-embed-text-v1.5
Chunk Size: 1000
Chunk Overlap: 200
Top K: 5
Relevance Threshold: 0.3

Chunk size and overlap matter more than most operators realize. Legal documents and technical specifications contain cross-references that span paragraph boundaries; aggressive chunking severs these relationships. Test retrieval quality with known questions against your corpus before declaring the RAG pipeline production-ready. The relevance threshold filters out low-confidence matches; setting it too low injects noise, while setting it too high causes false negatives. Start at 0.3 and adjust based on observed retrieval precision.

Security for ingested documents follows the same principles as any application handling sensitive data. Open WebUI stores uploaded files and vector indices in the mounted volume with filesystem permissions inherited from the Docker daemon. Restrict volume ownership to the container user, disable public sharing links, and audit access logs regularly. For legal-tech deployments where attorney-client privilege applies, confirm that no telemetry or analytics endpoints transmit document content externally; Open WebUI is fully offline-capable when configured correctly, but verify network traffic with tcpdump during initial setup.

What operational monitoring and maintenance routines prevent silent failures?

Local LLM stacks fail silently more often than cloud APIs. Ollama may stop responding to requests while the systemd service reports active; GPU memory may fragment causing intermittent slowdowns; Docker containers may restart without surfacing errors to users. Establish monitoring before you trust the system for real work.

  • Create a health-check cron job that queries /api/tags every five minutes and alerts on failure or response time exceeding 10 seconds.
  • Log Ollama inference metrics (tokens/sec, queue depth, model load times) to Prometheus or a simple rotating log file for trend analysis.
  • Schedule weekly ollama rm cleanup for unused model tags to reclaim disk space; quantized models accumulate quickly during experimentation.
  • Monitor GPU temperature and fan curves; sustained inference loads push consumer GPUs to thermal limits that trigger throttling after 30–60 minutes.
  • Back up the Open WebUI data volume nightly; SQLite corruption from unexpected power loss has caused complete data loss in production deployments I have reviewed.
Cron Health CheckEvery 5 minGET /api/tagsMetrics LoggerTokens/sec, queueRotating log / PromAlert HandlerEmail / webhookOn failure or slowNightly BackupVolume snapshotOffsite copyWeekly Cleanupollama rm unusedDisk reclamation
Operational monitoring pipeline: automated health checks feed metrics logging and alerting, while scheduled backups and cleanup prevent data loss and disk exhaustion.

Docker Compose deployments should include a watchdog sidecar or use Docker's built-in healthcheck directive with restart policies. Relying solely on restart: unless-stopped masks underlying issues; the container restarts successfully but continues failing the same way. Pair restart policies with external validation that confirms the application actually serves requests after restart.

When Should You Self-Host LLMs with Ollama and Open WebUI Instead of Using Cloud APIs?

The decision to self-host LLMs with Ollama and Open WebUI hinges on three factors: data sensitivity, usage volume, and tolerance for operational responsibility. If your workload involves client-confidential legal documents, internal business strategy, or regulated healthcare data, local inference eliminates third-party data exposure entirely. For high-volume use exceeding 2 million tokens per month, owned hardware typically breaks even within 6–12 months compared to OpenAI or Anthropic API pricing at 2026 rates.

However, self-hosting demands ongoing maintenance time. Model updates require manual testing against your specific prompts; GPU drivers need periodic upgrades; security patches for Docker and the host OS cannot be deferred indefinitely. Teams without dedicated DevOps capacity should budget 4–8 hours monthly for maintenance or consider hybrid approaches where sensitive workloads run locally and general-purpose queries use cloud APIs. For organizations planning broader automation initiatives, reviewing available AI automation tools and integration strategies helps position local inference as one component of a larger workflow rather than an isolated experiment.

Start with a single GPU workstation running the configuration above. Validate that inference quality meets your requirements before scaling to multi-GPU or clustered deployments. Most teams discover that 8B–12B models handle 80% of internal use cases adequately; chasing 70B parameter models without measured quality gaps wastes capital and complicates operations unnecessarily. Build incrementally, measure continuously, and treat your local LLM stack as production infrastructure deserving the same rigor as any other business-critical system.

If you need help architecting a private AI inference stack, integrating RAG pipelines with existing Laravel or WordPress systems, or evaluating whether self-hosting makes financial sense for your specific workload, reach out to discuss your requirements.

Frequently Asked Questions

You need at least 16GB RAM for 7B parameter models. For comfortable inference of 8B to 14B models like Llama 3 or Mistral, I recommend 32GB DDR5 RAM and an NVIDIA GPU with 12GB+ VRAM. CPU-only setups work but are significantly slower for production use.

Yes, both tools are open-source and free. Your only costs are hardware and electricity. Running a dedicated GPU server locally costs roughly NPR 15,000–25,000 monthly in power depending on usage, versus USD 200–500 monthly for comparable cloud GPU instances.

Install Ollama via curl -fsSL https://ollama.com/install.sh | sh. Then deploy Open WebUI using Docker: docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui ghcr.io/open-webui/open-webui:main. Both services start automatically and persist across reboots.

Yes, Ollama supports loading multiple models in memory if you have sufficient VRAM and RAM. On a 24GB VRAM GPU, I routinely keep Llama-3-8B and Mistral-7B loaded simultaneously. Models unload automatically after five minutes of inactivity unless pinned via the API keep_alive parameter.

Open WebUI connects to host.docker.internal:11434 by default when using the recommended Docker command. This special DNS name resolves to the host machine running Ollama. If connection fails, verify Ollama is listening on all interfaces by setting OLLAMA_HOST=0.0.0.0 in your systemd environment file.

Qwen2.5-Coder-32B and DeepSeek-Coder-V2 currently lead benchmarks for code generation. For machines with limited VRAM, CodeLlama-7B-Instruct remains reliable. In my experience integrating AI into Laravel development workflows, these models handle PHP 8.4 syntax and Vue 3 composition API correctly without hallucinating deprecated functions.

Enable authentication in Open WebUI admin settings immediately after installation. Create user accounts and disable public signup. For network-level security, place Nginx as a reverse proxy with SSL via Let's Encrypt and restrict port 3000 to localhost. Never expose Open WebUI directly to the internet without authentication.

Verify GPU offloading with ollama ps during inference. If layers show zero GPU allocation, reinstall CUDA drivers and ensure nvidia-smi detects your card. Common causes include mismatched CUDA versions, missing nvidia-container-toolkit for Docker, or insufficient VRAM forcing CPU fallback. Check Ollama logs for GPU initialization errors.

Yes, Ollama exposes a REST API at localhost:11434/api/chat compatible with OpenAI SDK format. I have integrated this into Laravel legal-tech portals for document summarization using Laravel HTTP client with streaming responses. Store API keys in .env and implement rate limiting to prevent resource exhaustion on your inference server.

Quantized GGUF models range from 4GB for 7B parameters to 20GB for 32B parameters. Ollama stores models in ~/.ollama/models/blobs. Plan for at least 100GB SSD space if testing multiple models. Use ollama list to audit installed models and ollama rm to remove unused ones. NVMe storage significantly improves model load times.

Yes, Open WebUI includes built-in RAG pipeline supporting PDF, DOCX, and text uploads. It uses sentence-transformers for embeddings stored in ChromaDB. For Nepal legal documents I have processed, chunk size 500 with overlap 50 produces accurate citations. Configure embedding model separately from chat model for optimal retrieval quality.

Update Ollama with curl -fsSL https://ollama.com/install.sh | sh which preserves downloaded models. Update Open WebUI by pulling latest Docker image and recreating container; the -v open-webui:/app/backend/data volume mount persists chats, users, and RAG collections. Always backup the Docker volume before major updates.

Yes, Ollama supports AMD ROCm on Linux for Radeon RX 7000 series and newer. Performance trails NVIDIA by 20-30% in my testing but remains viable. Install rocm-ollama package instead of standard build. Older AMD cards lack official support and will fall back to CPU inference regardless of configuration attempts.

First confirm Ollama is running with systemctl status ollama. Test connectivity via curl http://localhost:11434/api/tags. If Docker cannot reach host, add --network=host flag or verify host.docker.internal resolution. Check Open WebUI admin panel connection URL matches your Ollama endpoint. Restart both services after configuration changes.

Self-host when data privacy is critical, latency matters, or monthly API costs exceed NPR 15,000. For Nepal businesses handling sensitive legal or financial documents, local inference eliminates third-party data exposure. Cloud APIs remain better for sporadic usage, cutting-edge models requiring H100 clusters, or teams lacking hardware maintenance capacity.

Share this article

Quick Contact Options
Choose how you want to connect me: