How to Host Your Own WordPress Site on a VM with Docker

A beginner-friendly walkthrough of setting up a self-hosted WordPress environment using Ubuntu Server, VMware, and Docker.

Introduction

If you’ve ever wanted to run your own WordPress site instead of relying on a hosting provider, this guide walks through building a complete local WordPress environment from scratch — using a virtual machine and Docker. By the end, you’ll have a working WordPress site running in containers, accessible right from your browser.

This setup is great for:

  • Learning how WordPress, databases, and web servers fit together
  • Testing plugins/themes safely without touching a live site
  • Practicing DevOps basics like Docker and Git

What we’ll use:

  • VMware (to run a virtual machine)
  • Ubuntu Server (the OS)
  • Docker & Docker Compose (to run WordPress + database + web server as containers)

What You’ll Need

  • A computer with VMware installed (Workstation, Player, or Fusion)
  • An Ubuntu Server ISO
  • Basic comfort with the command line (copy-paste is fine!)

Step 1: Create the Virtual Machine

  1. Open VMware and create a new VM
  2. Select your Ubuntu Server ISO
  3. Allocate resources — for a small setup like this, 2 CPU cores and 4GB RAM is a reasonable starting point
  4. Set the network adapter to Bridged mode so the VM gets its own IP address on your home network, reachable directly from your laptop

Step 2: Install Ubuntu Server

Walk through Ubuntu’s installer:

  • Set your username and password
  • Enable OpenSSH server during installation (makes it easy to manage the VM remotely later)
  • Complete the install and reboot

Once it boots to a login prompt, you’re ready to go.

Update the system before continuing:

bash


Step 3: Install Docker

Docker lets us run WordPress, its database, and a web server as isolated containers — without manually installing and configuring each one on the OS.

bash

Verify it worked:

bash


Step 4: Set Up the Project Folder

Create a folder to hold all your configuration files:

bash

We’ll define credentials in a .env file, keeping secrets separate from the main config:

bash

.env


Step 5: Create the Docker Compose File

This file tells Docker what containers to run: a database, WordPress itself, and an Nginx web server to handle incoming requests.

bash

docker-compose.yml


Step 6: Configure Nginx

Create a config folder and a routing file for the site:

bash

site1.conf

Tip: Using $http_host (instead of $host) makes sure the port number is preserved when Nginx forwards requests — otherwise WordPress may redirect to a URL missing the port, causing a “refused to connect” error.


Step 7: Launch Everything

bash

All containers should show as Up.

Check the logs if anything looks off:

bash


Step 8: Access WordPress from Your Browser

Find your VM’s IP address:

bash

Then, from your laptop’s browser, visit:

You should land on the WordPress installation screen.
Fill in your site title, admin username, and password to complete the install.


Wrapping Up

At this point, you have a fully working, self-hosted WordPress site running in Docker containers on a virtual machine — completely isolated from your host system, and easy to tear down or rebuild at any time with:

bash

Where to go from here:

  • Add a second (or third) WordPress site by duplicating the database/WordPress service blocks with a new port
  • Push your configuration to GitHub so the whole environment can be rebuilt on another machine
  • Explore setting up HTTPS or a static IP for a more permanent setup

Self-hosting WordPress this way is a great, low-risk way to learn Docker, Linux server basics, and how a real web stack fits together — all without needing a live production server.


Have questions or run into issues following along? Drop a comment below!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top