Skip to content

valentindragan/wordpress-nginx-docker-compose

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Compose and WordPress

Build Status

Use WordPress locally with Docker using Docker compose

  • Dockerfile for extending a base image with a custom Docker image with automated build on Docker Hub
  • Custom domain for example myapp.local
  • Custom nginx config in ./nginx
  • Custom PHP php.ini config in ./config
  • Volumes for nginx, wordpress and mariadb
  • WordPress using Bedrock - modern development tools, easier configuration, and an improved folder structure
  • Composer
  • PhpMyAdmin
  • CLI scripts
    • Create a self signed SSL certificate for using https
    • Trust certs in macOS System Keychain
    • Setup the local domain in your in /etc/hosts

Setup

Requirements

  • Docker
  • Openssl for creatng the SSL cert. Install using Homebrew brew install openssl

Setup environment variables

Easily set your own local domain, db settings and more. Start by creating .env files, like the examples below.

For Docker and the cli scripts

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_

For WordPress

Copy .env-example in the src folder to .env and edit your preferences.

Use the following database settings:

DB_HOST=mysql:3306
DB_NAME=myapp
DB_USER=root
DB_PASSWORD=password

Create SSL cert

cd cli
./create-cert.sh

Note: OpenSSL needs to be installed.

Trust the cert in macOS Keychain

Chrome and Safari will trust the certs using this script.

In Firefox: Select Advanced, Select the Encryption tab, Click View Certificates. Navigate to where you stored the certificate and click Open, Click Import.

cd cli
./trust-cert.sh

Setup vhost in /etc/hosts

cd cli
./setup-hosts-file.sh

Follow the instructions.

Setup nginx config

Replace myapp.local in nginx/wordpress_ssl.conf with your own local domain of choice.

Install WordPress and Composer dependencies

docker-compose run composer intall

If you have Composer installed on your Mac you can also use cd src && composer install

Run

docker-compose up -d

docker-compose will 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

🚀 Open up https://myapp.local

PhpMyAdmin

PhpMyAdmin now comes installed as a service in docker-compose.

Open http://127.0.0.1:8080/

Notes:

When making changes to the Dockerfile, use:

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

Tools

wp-cli

docker exec -it myapp-wordpress bash
wp search-replace https://olddomain.com https://newdomain.com --allow-root

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

Changelog

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


Useful Docker Commands

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

About

Use WordPress with Docker using Docker Compose

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 79.5%
  • Shell 17.7%
  • Dockerfile 2.8%