Back to tutorials
Tutorial

Add an AI Chatbot to WordPress Using Open WebUI

Add Open WebUI to WordPress by self-hosting Open WebUI + Ollama on a VPS and embedding a secured chatbot with limits.

By Anurag Singh
Updated on Nov 16, 2026
Category: Tutorial
Share article
Add an AI Chatbot to WordPress Using Open WebUI

Your WordPress site answers the same questions on repeat: shipping times, pricing, refunds, and “how do I reset my password?” A self-hosted chatbot can handle a lot of that.

You also avoid sending visitor prompts to a third-party SaaS.

This tutorial shows how to add Open WebUI to WordPress. You’ll run Open WebUI + Ollama on your own VPS. You’ll lock down the endpoint (TLS, auth, CORS/embedding), set sensible limits, and embed a chat widget on your site.

What you’ll build (and what you won’t)

You’ll run:

  • Ollama (LLM runtime) on a VPS
  • Open WebUI (chat UI + simple API) behind Nginx with HTTPS
  • A WordPress embed that loads the chatbot safely from a separate domain/subdomain

You will not get perfectly accurate support answers out of the box. Base models can sound confident while being wrong.

If you need answers grounded in your docs with citations, you’ll add retrieval (RAG) later. For now, you’re building the infrastructure and a controlled way to expose it.

Infrastructure plan and resource sizing

Run the chatbot on its own host (VPS or dedicated server). Treat it like an application service. Don’t install it on the same box as production WordPress.

  • Minimum (CPU-only): 4 vCPU, 8–16 GB RAM, 80+ GB NVMe. Fine for light traffic and smaller quantized models.
  • Comfortable (CPU-only): 8 vCPU, 32 GB RAM. Better latency and concurrency, especially if you log and monitor.
  • GPU: optional. If you need low latency under load, use a GPU VPS/dedicated server with enough VRAM for your model.

For most WordPress help-chat use cases, start CPU-only with a quantized model. Measure first, then upgrade.

If you want steadier performance during traffic spikes, move to a GPU host later.

If you need a server to run this stack, a HostMyCode VPS gives you root access and clean isolation for an AI endpoint.

Prerequisites

  • A VPS running Ubuntu (22.04 LTS or newer). Debian also works with small command changes.
  • A domain or subdomain you control (example: chat.example.com).
  • Root or sudo access.

Tip: keep the chatbot on a separate subdomain from WordPress. This makes CORS and cookie behavior easier to reason about.

Step 1: Create DNS for your chatbot subdomain

Point chat.example.com to your VPS IP with an A/AAAA record. If you manage DNS at HostMyCode, you can do it from HostMyCode domains.

After DNS propagates, verify from your local machine:

dig +short chat.example.com

Step 2: Install Ollama (LLM runtime)

SSH into the VPS and install Ollama.

If you want extra service-hardening details, this walkthrough pairs well with the steps below: Install Ollama on Ubuntu VPS With Systemd.

On Ubuntu:

sudo apt update
sudo apt -y install curl ca-certificates
curl -fsSL https://ollama.com/install.sh | sudo sh

Check that the service is up:

sudo systemctl status ollama --no-pager

Pull a model. For your first site chatbot, start with a smaller instruct model. It helps keep latency under control:

ollama pull llama3.1:8b-instruct

Quick smoke test:

ollama run llama3.1:8b-instruct "Write a one-line greeting for a website help chat."

Step 3: Run Open WebUI with Docker

Open WebUI is simplest to run in Docker. Mount persistent storage so settings and user accounts survive restarts.

Install Docker:

sudo apt -y install apt-transport-https ca-certificates gnupg

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update
sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER

Log out and back in (or run newgrp docker) so your user can run Docker commands.

Create a directory for Open WebUI:

sudo mkdir -p /opt/openwebui
sudo chown -R $USER:$USER /opt/openwebui
cd /opt/openwebui

Create compose.yml:

cat > compose.yml <<'YAML'
services:
  openwebui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: openwebui
    restart: unless-stopped
    environment:
      - OLLAMA_BASE_URL=http://host.docker.internal:11434
      - WEBUI_AUTH=true
      - ENABLE_SIGNUP=false
      - DEFAULT_USER_ROLE=user
    volumes:
      - ./data:/app/backend/data
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - "127.0.0.1:3000:8080"
YAML

Bring it up:

docker compose up -d
docker compose ps

At this point, Open WebUI listens on 127.0.0.1:3000 only. That’s intentional.

Nginx will be your only public entrypoint.

If you want a deeper guide for this exact stack behind Nginx, this tutorial is a good add-on: Run Open WebUI With Ollama Behind Nginx Proxy.

Step 4: Put Nginx in front (TLS, headers, and basic safety)

Install Nginx and Certbot:

sudo apt -y install nginx
sudo apt -y install certbot python3-certbot-nginx

Create an Nginx server block for chat.example.com:

sudo tee /etc/nginx/sites-available/chat.example.com > /dev/null <<'NGINX'
server {
  listen 80;
  server_name chat.example.com;

  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    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;

    # WebSockets (Open WebUI uses them for streaming on some setups)
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

    # Basic timeouts (streaming responses can be long)
    proxy_read_timeout 3600;
    proxy_send_timeout 3600;
  }
}
NGINX

Enable the site and test:

sudo ln -s /etc/nginx/sites-available/chat.example.com /etc/nginx/sites-enabled/chat.example.com
sudo nginx -t
sudo systemctl reload nginx

Issue a Let’s Encrypt certificate:

sudo certbot --nginx -d chat.example.com

If you’d rather use Caddy for simpler TLS management, HostMyCode also has a guide: Set Up Let’s Encrypt With Caddy for a VPS Site.

Step 5: Create an admin user and lock down signups

Open https://chat.example.com in your browser.

  1. Create the first user account. In most Open WebUI deployments, the first user becomes an admin.
  2. Confirm that public signups are disabled (we set ENABLE_SIGNUP=false).
  3. In the admin settings, set a clear “system prompt” policy for the bot (next section).

This matters for cost control. If you leave signups open, strangers can create accounts and run your model on your dime.

On CPU, it doesn’t take many users to pin the machine.

Step 6: Define a “website helper” system prompt that won’t get you sued

Keep the goal narrow. Answer common site questions, route people to the right page, and avoid inventing policy.

In Open WebUI, create a model preset or default system message like this:

You are the help assistant for Example.com.
- If you are unsure, say you are not sure and suggest contacting support.
- Do not invent prices, guarantees, or legal terms.
- For account changes or payments, instruct the user to use the official account pages.
- Keep answers under 120 words unless the user asks for detail.
- If the user asks for confidential data, refuse.

This won’t eliminate hallucinations. It does reduce the chance of an expensive mistake.

Step 7: Add CORS and embedding rules (so only your site can load it)

There are two safe patterns for WordPress embedding:

  • Recommended: embed an iframe to a locked-down “public chat” page, with no admin features.
  • More complex: call an API from the browser. This requires tight CORS plus an auth strategy that doesn’t leak secrets.

This tutorial uses an iframe. It keeps auth and tokens out of your visitors’ browser JavaScript.

Add clickjacking and embedding controls in Nginx. Replace https://www.example.com with your real WordPress origin (and keep the scheme exactly right):

sudo sed -i 's/server_name chat.example.com;/server_name chat.example.com;\
\
  add_header X-Content-Type-Options nosniff always;\
  add_header Referrer-Policy no-referrer-when-downgrade always;\
  add_header Permissions-Policy "interest-cohort=()" always;\
\
  # Allow embedding ONLY on your WordPress site\
  add_header Content-Security-Policy "frame-ancestors https:\/\/www.example.com" always;\
  add_header X-Frame-Options "SAMEORIGIN" always;\
\
  # CORS is typically not needed for iframe embeds, but harmless for static assets\
  add_header Access-Control-Allow-Origin "https:\/\/www.example.com" always;\
  add_header Vary "Origin" always;/' /etc/nginx/sites-available/chat.example.com

sudo nginx -t && sudo systemctl reload nginx

Note: X-Frame-Options and frame-ancestors can conflict. Modern browsers prefer frame-ancestors.

If embedding fails, remove X-Frame-Options and rely on frame-ancestors only.

Step 8: Put Open WebUI behind an extra access gate (practical options)

Open WebUI has login. You should still protect the operator UI with an outer gate.

A few workable options:

  • Private admin via tunnel: keep the Open WebUI admin off the public internet, expose only the embedded public surface.
  • HTTP basic auth at Nginx for the whole site (quick and effective, but it also blocks visitors).
  • Two subdomains: one private for admin, one public for embed.

The cleanest setup is two subdomains:

  • admin-chat.example.com → Open WebUI full interface, restricted to your IP/VPN or a tunnel
  • chat.example.com → embed-only page (no signups, limited UI)

If you want the “private admin” approach without managing VPN users, follow this HostMyCode guide: Set Up Cloudflare Tunnel on a VPS for Private Admin.

Step 9: Rate limits and request size limits (don’t let one visitor melt the VPS)

Nginx can absorb a lot of low-effort abuse. Rate limiting won’t stop a determined attacker.

It does help with refresh loops, scraping, and casual spam.

Edit the Nginx site file:

sudo nano /etc/nginx/sites-available/chat.example.com

Add these lines inside the server { ... } block (near the top):

# Limit requests per IP (tune for your traffic)
limit_req_zone $binary_remote_addr zone=webui_per_ip:10m rate=30r/m;

Then inside location / add:

limit_req zone=webui_per_ip burst=10 nodelay;
client_max_body_size 2m;

Test and reload:

sudo nginx -t && sudo systemctl reload nginx

If your users paste long logs, bump client_max_body_size carefully. Oversized requests chew through RAM and bandwidth fast.

Step 10: Create an embed page that’s safe for the public

You’re balancing two things: making chat easy to reach and keeping the operator UI out of public hands.

A practical route is to publish a dedicated “Chat” page in Open WebUI (or a simplified view). Then embed that page in WordPress.

If you can’t isolate the UI cleanly, don’t embed the full interface. Use a small front-end that talks to your backend instead.

That’s more work, but it’s safer.

If you keep Open WebUI as the embedded surface, at minimum:

  • Disable signups (done)
  • Create a non-admin user for the embed experience
  • Ensure admin settings pages aren’t accessible without login
  • Restrict embedding via frame-ancestors (done)

For many sites, a “logged-out embed” won’t be acceptable. If you require login, consider offering the chatbot only to logged-in WordPress users (customer portal/membership area).

That takes custom SSO work, which is outside this tutorial.

Step 11: Add the chatbot to WordPress (Gutenberg + shortcode)

You’ll embed the chatbot with an iframe on a WordPress page (for example: /help/chat/).

Option A: Gutenberg Custom HTML block

Add a “Custom HTML” block and paste:

<div style="width:100%;max-width:900px;margin:0 auto">
  <iframe
    src="https://chat.example.com/"
    style="width:100%;height:720px;border:1px solid #e5e7eb;border-radius:12px"
    loading="lazy"
    referrerpolicy="no-referrer"
    allow="clipboard-read; clipboard-write"
  ></iframe>
</div>

Adjust the height for mobile.

If your theme adds horizontal padding, you may prefer removing max-width and letting it run full width.

Option B: Create a shortcode (keeps editors from breaking markup)

Add this to your theme’s functions.php (or, better, a tiny custom plugin):

function hmc_openwebui_chat_shortcode() {
  $src = 'https://chat.example.com/';
  return '<div style="width:100%;max-width:900px;margin:0 auto">'
    . '<iframe src="' . esc_url($src) . '" '
    . 'style="width:100%;height:720px;border:1px solid #e5e7eb;border-radius:12px" '
    . 'loading="lazy" referrerpolicy="no-referrer"></iframe>'
    . '</div>';
}
add_shortcode('openwebui_chat', 'hmc_openwebui_chat_shortcode');

Then put [openwebui_chat] on any page.

Step 12: Add “guardrails” on the WordPress side (UX and policy)

Tell visitors what this is—and what it isn’t. Put a short note above the embed:

  • “This assistant can be wrong. For billing and account issues, contact support.”
  • “Don’t paste passwords, API keys, or private customer data.”

If your site is in a regulated niche (health, finance, legal), keep the bot tightly scoped. Or don’t expose it publicly at all.

Step 13: Basic hardening checklist (do this before you announce it)

  • Firewall: only allow 80/443 inbound; keep 3000 closed (it’s on loopback already).
  • Fail2ban: protect Nginx from brute-force and noisy scanners. Guide: Set Up Fail2ban for Nginx on Ubuntu VPS.
  • Backups: back up /opt/openwebui/data and note your restore steps. A backup you can’t restore is noise.
  • Model choice: if CPU is struggling, switch to a smaller model or quantize. This tutorial helps you choose quantization levels: llama.cpp Quantization: Pick Q4 vs Q5 vs Q8.

Step 14: Quick diagnostics (latency, memory pressure, and common mistakes)

Check CPU and RAM pressure:

sudo apt -y install htop
htop

If the box swaps heavily, replies will feel like timeouts. Add RAM, reduce model size, or add swap as a temporary band-aid.

Swap won’t fix real capacity issues.

Confirm Open WebUI can reach Ollama:

curl -s http://127.0.0.1:11434/api/tags | head

Check container logs:

docker logs --tail=200 openwebui

If the iframe is blank, it’s usually one of these:

  • Your Content-Security-Policy frame-ancestors doesn’t match the exact WordPress origin.
  • You set X-Frame-Options in a way that blocks embedding.
  • Mixed content (embedding HTTP in an HTTPS page). Always embed https://.

Honest limitations (plan for them)

  • CPU-only is slower: fine for low traffic, but it can’t handle many concurrent chats without queueing.
  • Public bots get abused: expect prompt spam and jailbreak attempts. Rate limit and keep signups off.
  • Hallucinations happen: add disclaimers in your UI, and don’t treat the bot as the final word on policy.

If you want the chatbot to answer from your real docs with citations, the next step is RAG (embeddings + vector search). HostMyCode has a practical RAG track starting here: Self-Host a PrivateGPT RAG Chatbot With Qdrant.

If you want a WordPress chatbot you control end-to-end, run Open WebUI + Ollama on your own server and keep WordPress isolated. Start with a HostMyCode VPS, then move to managed VPS hosting if you don’t want to handle updates, monitoring, and hardening yourself.

FAQ

Should I run Open WebUI on the same server as WordPress?

Usually no. Inference is bursty and can starve PHP-FPM/MySQL at the worst time. Keep it on a separate VPS and connect over HTTPS.

Do I need a GPU to add Open WebUI to WordPress?

No. A CPU-only VPS works for smaller quantized models and light traffic. If you need fast responses for many users, plan a GPU host.

How do I stop the public from using my Open WebUI instance?

Disable signups, require login, and restrict embedding with Content-Security-Policy: frame-ancestors. Add Nginx rate limits and consider a private admin subdomain.

Can the chatbot answer using my WordPress knowledge base?

Not reliably with a base model alone. Use RAG (vector search over your docs) so the bot can retrieve and quote your actual pages.

Summary

You now have a practical path to add Open WebUI to WordPress: run Ollama + Open WebUI on a VPS, front it with Nginx + TLS, lock down signups, set embedding rules, and embed it with an iframe.

For production use, plan for traffic spikes. Keep the AI service isolated from WordPress.

A HostMyCode VPS is an easy starting point, and you can upgrade resources as usage grows.