How to Quickly Install WordPress Locally for Development via Docker

How to Quickly Install WordPress Locally for Development

Setting up a local WordPress environment is one of the fastest and safest ways to test plugins, themes, or build new client sites without risking a live server. In this guide, I’ll walk you through how to install WordPress locally using Docker — the modern developer’s tool of choice.

Whether you’re a freelance web developer in Melbourne or a marketing coordinator from Perth trying to prototype a campaign landing page, this method will work seamlessly on your machine.

Prefer watching over reading? You can check out the full tutorial on YouTube in the player below.

Or if you’re more of an old-school type who likes a proper walkthrough in text — just scroll down. Everything’s laid out step by step, like back in the good days of real how-to blogs.

Table of Contents

  1. Why Install WordPress Locally?
  2. Local Installation Options for WordPress
  3. Prerequisites
  4. Step-by-Step: Local WordPress Installation Using Docker
    1. 1. Create Project Structure
    2. 2. Set Up .env File
    3. 3. docker-compose.yml Configuration
    4. 4. Launch Containers
    5. 5. Access WordPress and Developer Tools
  5. MySQL Performance Tuning for WordPress
  6. Frequently Asked Questions
  7. Download Ready-to-Use Project
  8. Final Thoughts

Why Install WordPress Locally?

  • Full control over the environment (PHP version, extensions, mail handling)
  • Zero hosting costs
  • Instant reloads and file access
  • No risk of breaking production

Local Installation Options for WordPress

ToolTypeProsCons
DockerContainer-basedConfigurable, reproducible, modern dev standardsRequires terminal knowledge, initial setup
XAMPPApp bundleEasy GUI, quick start for beginnersHard to version control, conflicts with other services
MAMPApp bundlePopular on Mac, simple interfaceFree version lacks advanced features
LocalWPSpecialised toolZero-config, good for designersLess flexible, can be resource-heavy
VagrantVM-basedIsolation, full OS-level controlSlower performance, higher resource usage

Prerequisites

  • Docker Desktop installed (Mac, Windows, Linux)
  • Basic knowledge of terminal or command prompt

Step-by-Step: Local WordPress Installation Using Docker

1. Create Project Structure

mkdir my-wp-dev && cd my-wp-dev
mkdir wordpress php-config mysql-config
echo "upload_max_filesize=64M\npost_max_size=64M" > php-config/php.ini

2. Set Up .env File

COMPOSE_PROJECT_NAME=mywp
PROJECT_PORT=8000
PMA_PORT=8080
MAILHOG_HTTP_PORT=8025
MAILHOG_SMTP_PORT=1025
WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_USER=wordpress
WORDPRESS_DB_PASSWORD=wordpress
MYSQL_ROOT_PASSWORD=root

3. docker-compose.yml Configuration

version: '3.8'

services:
  wordpress:
    image: wordpress:latest
    ports:
      - "${PROJECT_PORT:-8000}:80"  # Host:Container — WordPress UI
    volumes:
      - ./wordpress:/var/www/html
      - ./php-config/php.ini:/usr/local/etc/php/conf.d/custom.ini
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
      WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
      WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME}
    depends_on:
      - db
      - mailhog

  db:
    image: mysql:8.0
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_DATABASE: ${WORDPRESS_DB_NAME}
      MYSQL_USER: ${WORDPRESS_DB_USER}
      MYSQL_PASSWORD: ${WORDPRESS_DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - ./mysql-data:/var/lib/mysql
      - ./mysql-config:/etc/mysql/conf.d

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - "${PMA_PORT:-8080}:80"  # phpMyAdmin access on localhost
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    depends_on:
      - db

  mailhog:
    image: mailhog/mailhog
    ports:
      - "${MAILHOG_HTTP_PORT:-8025}:8025"  # MailHog web UI
      - "${MAILHOG_SMTP_PORT:-1025}:1025"  # MailHog SMTP (for WP emails)

4. Launch Containers

docker-compose up -d

5. Access WordPress and Developer Tools

Create a file to inspect PHP:

<?php phpinfo(); ?>

MySQL Performance Tuning for WordPress

Create file mysql-config/wp.cnf with:

[mysqld]
max_allowed_packet = 64M
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
default_authentication_plugin = mysql_native_password
sql_mode = ""

This improves large DB imports, plugin compatibility, and query reliability.

Frequently Asked Questions

How is Docker better than XAMPP or MAMP?

  • Environment is reproducible across teams
  • Can be committed to version control
  • No conflicts with host OS services

Can I run multiple projects?

Yes. Use different COMPOSE_PROJECT_NAME and port values in .env.

Can I access the database?

Yes, via:

Can I test emails locally?

Yes. MailHog captures WordPress emails: http://localhost:8025

Download Ready-to-Use Project

You can download the full ready-to-use project on GitHub:
👉 https://github.com/gynsus/wordpress-docker-local-dev

Final Thoughts

With Docker, you get a full WordPress stack locally in minutes. It’s easy to set up, fast to use, and ideal for any developer or marketer working with WordPress daily.