Wordpress

Setup

My current Wordpress setup runs these services:

site

An Apache server, with a local source directory added as bind mount.

db

A MySQL server, with its database stored on a Docker volume.

pma

A PhpMyAdmin server, to manage the database(s).

Diagram

Configuration remarks:

  • You need to set your own local user and group id in .env.

  • Also, the .env file has hard-coded values for WORDPRESS_HOME and WORDPRESS_SITEURL, using localhost as the server.

  • For this to work, the application server in docker-compose.yml has the setting:

        extra_hosts:
          - localhost:host-gateway

Example files

.env
# Environment variables for Docker
# Add as `.env` in the project root directory

# Optional: by default Docker generates a project name based on the base directory of docker-compose.yml
# COMPOSE_PROJECT_NAME=myproject

# Numerical user and group id for the current user (find them with the command `id`)
# This will run Apache as the current user, and makes installing and updating from the front-end possible
UID=1001
GID=1001

# Ports for the web interfaces of Wordpress and PHPMyAdmin: localhost:<PORT>
# When running multiple environments at the same time, assign unique port numbers
WORDPRESS_PORT=8001
PMA_PORT=8002

# Hardcode the Wordpress URLs so that settings in the database are ignored
# (Makes it easier to work with a copy of the live database.)
WORDPRESS_HOME=http://localhost:${WORDPRESS_PORT}
WORDPRESS_SITEURL=http://localhost:${WORDPRESS_PORT}

# Local directory where Wordpress sources reside
# This will be mounted into the Wordpress container
WORDPRESS_SOURCES=./htdocs/

# Extra instructions to evaluate in wp-config.php
# Can be given as PHP instructions, or read from a file
WORDPRESS_CONFIG_EXTRA=
WORDPRESS_CONFIG_EXTRA_FILE=wp-config-extra-dev.php

# Database info.
# MySQL is run as local service 'db' and can therefore be reached as host 'db'
WORDPRESS_DB_HOST=db
WORDPRESS_DB_USER=root
WORDPRESS_DB_PASSWORD=local
WORDPRESS_DB_ROOT_PASSWORD=local

WORDPRESS_DB_NAME=mydatabase
docker-compose.yml
version: "3.1"
services:
  site:
    image: wordpress:php8.1-apache
    depends_on:
      - db
    ports:
      - "${WORDPRESS_PORT}:80"
    extra_hosts:
      - localhost:host-gateway
    environment:
      WORDPRESS_HOME: ${WORDPRESS_HOME}
      WORDPRESS_SITEURL: ${WORDPRESS_SITEURL}
      WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST}
      WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
      WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
      WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME}
      WORDPRESS_CONFIG_EXTRA_FILE: ${WORDPRESS_CONFIG_EXTRA_FILE}
      WORDPRESS_CONFIG_EXTRA: ${WORDPRESS_CONFIG_EXTRA}
      APACHE_RUN_USER: "#${UID}"
      APACHE_RUN_GROUP: "#${GID}"
    volumes:
      - ${WORDPRESS_SOURCES}:/var/www/html

  db:
    image: mysql:8.0
    environment:
      MYSQL_DATABASE: ${WORDPRESS_DB_NAME}
      MYSQL_ROOT_PASSWORD: ${WORDPRESS_DB_ROOT_PASSWORD}
    volumes:
      - wpdb:/var/lib/mysql

  pma:
    image: phpmyadmin
    depends_on:
      - db
    ports:
      - "${PMA_PORT}:80"
    environment:
      PMA_USER: ${WORDPRESS_DB_USER}
      PMA_PASSWORD: ${WORDPRESS_DB_PASSWORD}
      UPLOAD_LIMIT: 100M
      MYSQL_ROOT_PASSWORD: ${WORDPRESS_DB_ROOT_PASSWORD}

volumes:
  wpdb:
chevron_left
chevron_right
Twitter LinkedIn Github Gitlab Meetup RSS Miro Trello Zotero Hypothesis