Stable Diffusion WebUI: A Self-Hosted AI Image Generator on Your VPS

Why Bother Self-Hosting an Image Generator?

Paid image generators are convenient, but three things made me want to run one myself. First, cost: a monthly subscription keeps running, while a one-time setup on your VPS only costs you the server you already own. Second, privacy: your prompts and images never pass through a third party's servers. Third, control: you can swap models, install extensions, and set your own limits — instead of following a platform's rules.

AUTOMATIC1111 Stable Diffusion WebUI is the most popular open source web interface for Stable Diffusion. It gives you a prompt box, image size settings, and a results gallery, all in the browser. Below I'll show you how to install it on a VPS — with one honest statement up front: this workload needs a GPU to be enjoyable.

Being Honest About Hardware: GPU Ideal, CPU Possible but Slow

This is the part other tutorials most often exaggerate, so let's get it straight:

VPS with an NVIDIA GPUCPU-only VPS
One 512×512 image, 20 stepsSeconds to tens of secondsMinutes
Large resolutions (768×768 and up)Still comfortableSlower and slower, can fail for lack of RAM
Models you can useFreely, including large modelsSmall models only, and still slow
Good forRegular useOccasional experiments

Exact numbers depend on the card and the model — as a rough guide, on a 12 GB card, one 20-step image generally finishes in 10–30 seconds. On CPU, the same image can take many times longer. So if you seriously want to use this generator every day, pick a VPS with an NVIDIA GPU. If you just want to try it out and learn, a CPU VPS can still work — as long as you're patient and stick to small models and resolutions.

One disk requirement is also worth noting: set aside at least 10 GB of free space. On its first run, WebUI downloads PyTorch and the default model checkpoint, which together run to several GB.

Step 1: Prepare the Server and Check the GPU

Log in to the VPS over SSH, then install the basic dependencies:

sudo apt update && sudo apt upgrade -y
sudo apt install wget git python3 python3-venv libgl1 libglib2.0-0 -y

If you're on a GPU VPS, make sure the NVIDIA driver is installed and detected:

nvidia-smi

This command should display the card and driver information. Many GPU VPS providers already ship images with the driver installed — in that case, this step is just verification. If nvidia-smi isn't found, install the driver from your VPS provider before continuing; without a driver, WebUI will fall back to the slow CPU mode.

Step 2: Download and Run WebUI

Download the official AUTOMATIC1111 repository, then run its script:

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
cd stable-diffusion-webui
./webui.sh

Don't be surprised if the first run takes a while — it can be 10–20 minutes. The script builds its own Python virtual environment, downloads PyTorch, and fetches the default model checkpoint (around 4 GB). During this process, keep the terminal open and the SSH connection alive.

When it finishes, you'll see a local address in the log, usually http://127.0.0.1:7860. That address is deliberately only reachable from inside the server — and that's a good thing, because we don't want this interface exposed raw to the internet.

Step 3: Access It Safely via SSH Tunnel

Don't reconfigure WebUI to listen on all addresses (--listen) without protection. The safest way for personal use is an SSH tunnel: from your laptop, run:

ssh -L 7860:127.0.0.1:7860 user@IP-VPS-Anda

Then open http://127.0.0.1:7860 in your laptop's browser. You're now reaching WebUI over an encrypted SSH connection, as if WebUI were running on your laptop itself. If you later decide to expose it through a reverse proxy, add authentication (WebUI supports basic auth via the --gradio-auth flag) and HTTPS — never leave this interface open without a login.

To keep WebUI running in the background after SSH closes, you can make it a systemd service. Create the file /etc/systemd/system/sd-webui.service:

[Unit]
Description=Stable Diffusion WebUI
After=network.target

[Service]
User=user-anda
WorkingDirectory=/home/user-anda/stable-diffusion-webui
ExecStart=/home/user-anda/stable-diffusion-webui/webui.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target

Adjust the user and paths to match your server, then:

sudo systemctl daemon-reload
sudo systemctl enable --now sd-webui

Step 4: Create Your First Image

In the txt2img tab, fill in the prompt box with a description of the image you want, for example: "a cozy mountain cabin at dusk, warm light in windows, photorealistic". Also fill in the negative prompt — things you don't want — for example: "blurry, low quality, watermark". A negative prompt is often what separates a mediocre result from one worth keeping.

Set the size to 512×512 for your first try, leave the step count at its default, then click Generate. On GPU, the result appears within seconds to tens of seconds. On CPU, wait longer and don't panic if the process looks idle — it's working, not stuck.

Once your first image succeeds, experiment with three levers: a more specific prompt, the step count (more steps usually mean more detail, but also more time), and the seed (the same number produces the same image from the same prompt — handy for reproducing a result you liked).

Step 5: Add Models and Extensions

The default model is only a starting point. You can download other models from Hugging Face or Civitai, then place them in the models/Stable-diffusion/ folder inside the WebUI directory. After that, refresh the model list in the interface and the new model will appear.

Two things you shouldn't skip here. First, check each model's license before using it for commercial projects — not every model is free for all uses. Second, download models only from sources you trust; a model file is executed code, so an untrustworthy source is a security risk.

From the Extensions tab, you can also install popular extensions like ControlNet (which controls image composition with sketches or poses). Extensions widen what WebUI can do without you having to install a new application.

To update WebUI to the latest version:

cd stable-diffusion-webui
git pull
./webui.sh

As usual, back up your model and output folders before updating — models you downloaded yourself won't be re-downloaded automatically if they're lost.

Final Checklist

  • nvidia-smi shows a GPU (or you're knowingly running in slow CPU mode)
  • ./webui.sh finishes without errors and the log shows the address 127.0.0.1:7860
  • The SSH tunnel is active and the interface opens from your laptop's browser
  • Your first image was created from the txt2img tab
  • WebUI isn't exposed raw to the internet (tunnel, or reverse proxy + authentication)
  • Model and output folders are included in your backup schedule

Closing

Self-hosting an image generator isn't about beating paid services at everything — paid services are still quicker to set up. The advantage lies elsewhere: no subscription, no queue, your prompts never leave your own server, and you can swap models whenever you like. With a decent GPU, the experience is already very comfortable for everyday use.

Also read: Ollama dan Open WebUI: Menjalankan LLM Lokal di VPS, AI Gateway Pribadi: Satu Endpoint untuk Semua Model, and WireGuard: Bangun VPN Pribadi di VPS.

What image would you create first with your own model? Write your dream prompt in the comments — it might become the idea for the next article.

Komentar