• Stars
    star
    728
  • Rank 62,237 (Top 2 %)
  • Language
    CSS
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run WordPress with nginx using Docker Compose.

Docker Compose and WordPress

Donate

Use WordPress locally with Docker using Docker compose

Contents

  • A Dockerfile for extending a base image and using a custom Docker image with an automated build on Docker Hub
  • PHP 8.1
  • Custom domain and HTTPS support. So you can use for example https://myapp.local
  • Custom nginx config in ./nginx
  • Custom PHP php.ini config in ./config
  • Volumes for nginx, wordpress and mariadb
  • Bedrock - modern development tools, easier configuration, and an improved secured folder structure for WordPress
  • Composer
  • WP-CLI - WP-CLI is the command-line interface for WordPress.
  • MailHog - An email testing tool for developers. Configure your outgoing SMTP server and view your outgoing email in a web UI.
  • PhpMyAdmin - free and open source administration tool for MySQL and MariaDB
    • PhpMyAdmin config in ./config
  • CLI script to create a SSL certificate

Instructions

Requirements

Install mkcert:

brew install mkcert
brew install nss # if you use Firefox
Setup

Setup Environment variables

Both step 1. and 2. below are required:

1. For Docker and the CLI script (Required step)

Copy .env.example in the project root to .env and edit your preferences.

Example:

IP=127.0.0.1
APP_NAME=myapp
DOMAIN="myapp.local"
DB_HOST=mysql
DB_NAME=myapp
DB_ROOT_PASSWORD=password
DB_TABLE_PREFIX=wp_

2. For WordPress (Required step)

Edit ./src/.env.example to your needs. During the composer create-project command described below, an ./src/.env will be created.

Example:

DB_NAME='myapp'
DB_USER='root'
DB_PASSWORD='password'

# Optionally, you can use a data source name (DSN)
# When using a DSN, you can remove the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST variables
# DATABASE_URL='mysql://database_user:database_password@database_host:database_port/database_name'

# Optional variables
DB_HOST='mysql'
# DB_PREFIX='wp_'

WP_ENV='development'
WP_HOME='https://myapp.local'
WP_SITEURL="${WP_HOME}/wp"
WP_DEBUG_LOG=/path/to/debug.log

# Generate your keys here: https://roots.io/salts.html
AUTH_KEY='generateme'
SECURE_AUTH_KEY='generateme'
LOGGED_IN_KEY='generateme'
NONCE_KEY='generateme'
AUTH_SALT='generateme'
SECURE_AUTH_SALT='generateme'
LOGGED_IN_SALT='generateme'
NONCE_SALT='generateme'
Option 1). Use HTTPS with a custom domain
  1. Create a SSL cert:
cd cli
./create-cert.sh

This script will create a locally-trusted development certificates. It requires no configuration.

mkcert needs to be installed like described in Requirements. Read more for Windows and Linux

1b. Make sure your /etc/hosts file has a record for used domains. On Windows the hosts file can be find at C:\Windows\System32\drivers\etc. Make sure to open it with admin rights.

sudo nano /etc/hosts

Add your selected domain like this:

127.0.0.1 myapp.local
  1. Continue on the Install step below
Option 2). Use a simple config
  1. Edit nginx/default.conf.conf to use this simpler config (without using a cert and HTTPS)
server {
    listen 80;

    root /var/www/html/web;
    index index.php;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    client_max_body_size 100M;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass wordpress:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
  1. Edit the nginx service in docker-compose.yml to use port 80. 443 is not needed now.
  nginx:
    image: nginx:latest
    container_name: ${APP_NAME}-nginx
    ports:
      - '80:80'
  1. Continue on the Install step below
Install
docker-compose run composer create-project
Run
docker-compose up

Docker Compose will now start all the services for you:

Starting myapp-mysql    ... done
Starting myapp-composer ... done
Starting myapp-phpmyadmin ... done
Starting myapp-wordpress  ... done
Starting myapp-nginx      ... done
Starting myapp-mailhog    ... done

🚀 Open https://myapp.local in your browser

PhpMyAdmin

PhpMyAdmin comes installed as a service in docker-compose.

🚀 Open http://127.0.0.1:8082/ in your browser

MailHog

MailHog comes installed as a service in docker-compose.

🚀 Open http://0.0.0.0:8025/ in your browser

Tools

Update WordPress Core and Composer packages (plugins/themes)

docker-compose run composer update

Use WP-CLI

docker exec -it myapp-wordpress bash

Login to the container

wp search-replace https://olddomain.com https://newdomain.com --allow-root

Run a wp-cli command

You can use this command first after you've installed WordPress using Composer as the example above.

Update plugins and themes from wp-admin?

You can, but I recommend to use Composer for this only. But to enable this edit ./src/config/environments/development.php (for example to use it in Dev)

Config::define('DISALLOW_FILE_EDIT', false);
Config::define('DISALLOW_FILE_MODS', false);

Useful Docker Commands

When making changes to the Dockerfile, use:

docker-compose up -d --force-recreate --build

Login to the docker container

docker exec -it myapp-wordpress bash

Stop

docker-compose stop

Down (stop and remove)

docker-compose down

Cleanup

docker-compose rm -v

Recreate

docker-compose up -d --force-recreate

Rebuild docker container when Dockerfile has changed

docker-compose up -d --force-recreate --build
Changelog

2022-05-28

2022-05-28

  • Use php:8.0-fpm-alpine as the base image on the image in Dockerfile

2022-05-28

  • Updated the Docker image to use PHP 8

2021-08-04

  • Updated to WordPress 5.8.0

2021-03-16

  • Changed root .env-example to .env.example to match the git ignore patterns. Thanks @scottnunemacher

2021-03-05

  • Clarify steps in the readme

2021-03-02

  • Fixed a misstake so instead of ./src/.env-example, it should be ./src/.env.example.
  • Redirect HTTP to HTTPS. Thanks @humblecoder

2021-01-02

  • Use NGINX_ENVSUBST_TEMPLATE_SUFFIX. Use a template and better substution of ENV variables in nginx config.

2020-10-04

  • Added mariadb-client (Solves #54)

2020-09-15

  • Updated Bedrock. Update WordPress to 5.5.1 and other composer updates.

2020-07-12

2020-05-03

  • Added nginx gzip compression

2020-04-19

  • Added Windows support for creating SSH cert, trusting it and setting up the host file entry. Thanks to @styssi

2020-04-12

  • Remove port number from DB_HOST. Generated database connection error in macOS Catalina. Thanks to @nirvanadev
  • Add missing ENV variable from mariadb Thanks to @vonwa

2020-03-26

2020-02-06

  • Readme improvements. Explain /etc/hosts better

2020-01-30

  • Use Entrypoint command in Docker Compose to replace the domain name in the nginx config. Removing the need to manually edit the domain name in the nginx conf. Now using the .env value DOMAIN
  • Added APP_NAME in .env-example Thanks to @Dave3o3

2020-01-11

  • Added .env support for specifying your own app name, domain etc in Docker and cli scripts.
  • Added phpMyAdmin. Visit http://127.0.0.1:8080/

2019-08-02

More Repositories

1

acf-fold-flexible

ACF Fold Flexible Content
JavaScript
61
star
2

checkbix

Simple lightweight vanilla Javascript plugin for enhancing checkboxes.
CSS
60
star
3

Unsplash

Unsplash for Sublime Text
Python
43
star
4

radar

A simple technology radar map (made famous by Thoughtworks)
CSS
23
star
5

kap-cloudinary

Kap plugin - Share on Cloudinary
JavaScript
16
star
6

alfredinary

Take a screenshot, upload it to Cloudinary. Get back https image link to clipboard.
JavaScript
13
star
7

jurge

Jekyll on Surge
HTML
12
star
8

Rename-Post-to-News

Sometimes you just need a post type to be called news, but maybe you dont want/can't/are to lazy to create a separate post type for this. This little plugin renames the build in post type (Post) to News. It also changes all the labels and replaces the pin icon with a pencil icon.
PHP
11
star
9

wordpress-nginx-docker-compose-image

Docker Image for wordpress-nginx-docker-compose
Dockerfile
9
star
10

Update-From-Bottom

Shows two extra buttons (Scroll to top and Publish/Update) in the bottom of the screen when user scrolls near bottom. Suitable for posts and pages with a lot of meta boxes, or when edit.php just tends to get very long.
PHP
9
star
11

system-backup-list

Backup a list of things on your computer to Dropbox
Shell
9
star
12

avanza-night-mode

🌙 All The Cool Kids Are Night Trading. Make it easier on the eyes
CSS
8
star
13

replace-images

Chrome Extension for replacing images in your current tab, different categories available!
JavaScript
8
star
14

staytube

Dedicated to great full length concerts. Exploring the concept of using "Youtube as a CMS".
JavaScript
7
star
15

get-starred-pocketcasts-episodes

Get your starred Pocket Casts episodes
JavaScript
6
star
16

wp-fresh

Get production database and media (wp-content/uploads) synced to your development environment. Fresh!
Shell
6
star
17

simple-history-cards

Card based layout addon for Simple History by Pär Thernström. Also showing icons indicating user action.
JavaScript
6
star
18

topdash

Like OS X admin bar menu icons, but for WordPress. Easy access to common tasks in the top right admin bar.
PHP
5
star
19

hemterest

Chrome Extension that lets you beautify Hemnet with Pinterest like style gallery instead of the default image slider.
JavaScript
5
star
20

og-rescrape

Click a button in wp-admin to rescrape Facebook Open Graph data.
PHP
5
star
21

albumcoverfinder

Album Cover Finder for WordPress
PHP
5
star
22

obfuscate-chrome

Simple Chrome Extension that obfuscates all text on the current webpage
JavaScript
5
star
23

scroll-showoff

Chrome Extension. Click the browser button and lean back while the page scrolls down slowly. Perfect for a screen recording.
JavaScript
5
star
24

jekyllbase

Minimal Jekyll starter using Basscss and Gulp.
CSS
5
star
25

cheeseburgericon

When common practices and trends should be questioned :)
HTML
5
star
26

localhttps

Use a self signed local SSL cert on macOS for local development
Shell
4
star
27

Are-You-Sure

Simple WordPress plugin that adds confirmation dialogue to the Publish button
PHP
4
star
28

chrome-allabolag

Chrome Extension for opening up current selection on http://www.allabolag.se
JavaScript
4
star
29

mutebot

A collection of regular expressions for Tweetbot to mute tweets in your timeline and mentions.
HTML
4
star
30

fruitage

Chrome Extension for Harvestapp.com that adds extra columns on invoices and reports, showing figures/balance/totals without 25% VAT
JavaScript
3
star
31

di-sans-paywall

Enjoy http://weekend.di.se/ without a Paywall. Read full length articles and reviews.
CSS
3
star
32

postpone

Publish In 1 hour, Tomorrow 8am, Tomorrow after lunch, Tonight, Next monday or Next month
PHP
3
star
33

trello-code-button

This extension adds a new shiny button for adding code in a Trello comment.
JavaScript
3
star
34

dotfiles

Dotfiles by Urban Sanden
Shell
3
star
35

searchable-awesome-public-datasets

Blazing fast search a list of a topic-centric public data sources in high quality
JavaScript
3
star
36

cloudways-app-setup

Create an application on Cloudways via their API
JavaScript
3
star
37

emojifun

😁 Simple emoji search
2
star
38

prisjakt-chrome

Chrome Extension for searching selected text in swedish price comparison service Prisjakt
JavaScript
2
star
39

wpjazz

The Music Behind The Releases. In honor of the Jazz musicians.
JavaScript
2
star
40

kermit

Beautiful Markdown theme for Sublime Text
2
star
41

admin-octicons

Use the great Github Octicons anywhere in wp-admin.
PHP
2
star
42

docker-compose-nginx-multiple-sites

Simple example using multiple https websites together
DIGITAL Command Language
2
star
43

Susyhelper

Just a simple structure/helper for debugging Susy2 grids
CSS
2
star
44

jekyllbase-aws

Fork of my Jekyll starter Jekyllbase https://github.com/urre/jekyllbase. Jekyllbase AWS is for deploying your Jekyll site to Amazon S3.
CSS
2
star
45

chock.press

Having fun with Swedish evening news.
JavaScript
2
star
46

WordPress-Start-Settings

Wp Start Settings
PHP
2
star
47

gulp-ftp-deploy

Must deploy to an old ftp server? Look no further.
JavaScript
2
star
48

gradvis

Gradvis är ett Chrome-tillägg som förbättrar läsupplevelsen på www.gradvall.se samt skapar automatiska Spotify-länkar
JavaScript
2
star
49

Benson

Just a simple color scheme for iTerm.app
2
star
50

post-expirator

Swedish translation of WordPress plugin Post Expirator
1
star
51

surfmangd

A fuzzy Mobile Data Plan Usage Calculator.
JavaScript
1
star
52

alfred-vvv-dbexport

Alfred Workflow for exporting databases from VVV
Shell
1
star
53

greycolors

Want grey hex colors?
JavaScript
1
star
54

branch-from-ticket-firefox

Firefox Extension that creates a git branch name from a Jira Ticket number and title.
JavaScript
1
star
55

custom-admin-bar-menus

Custom Admin Bar Menus
PHP
1
star
56

done-last-month

Save a done.txt of Trello cards added to the Done list in a specific board, for a certain month.
JavaScript
1
star
57

git-branch-name-from-jira-ticket

Create a git branch name from a JIRA Ticket
JavaScript
1
star
58

raycast-discogs-lastfm

Raycast Script command to browse Discogs from the currently playing album
Shell
1
star
59

Wells

http://wells.surge.sh
CSS
1
star
60

codeship-dashboard

This extension just redirects https://codeship.com to the Dashboard https://app.codeship.com/home
JavaScript
1
star
61

chrome-tradera

Chrome Extension for searching selected text on tradera.com
JavaScript
1
star
62

jazztips-spotify-app

Jazztips Spotify App
JavaScript
1
star
63

tinybrowse

Simple tool just to frame your development site or real site in a little computer
CSS
1
star