GithubHelp home page GithubHelp logo

balfourwong / wordpress-nginx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from urre/wordpress-nginx-docker-compose

0.0 1.0 0.0 8.68 MB

Run WordPress with nginx using Docker Compose.

Shell 29.99% PHP 58.89% Dockerfile 7.54% Batchfile 3.58%

wordpress-nginx's Introduction

Docker Compose and WordPress

Build Status

Donate

Use WordPress locally with Docker using Docker compose

This setup comes shipped with:

  • A Dockerfile for extending a base image and using a custom Docker image with an 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
  • 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 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

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

Create SSL cert

macOS and Linux

cd cli
./create-cert.sh

Note: OpenSSL needs to be installed.

Windows

Use the bat file in in ./cli/windows scripts/create-cert.bat

Trust the cert

Add to 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

Windows

Follow the instructions in ./cli/windows scripts/trust-cert.txt

Add the local domain in /etc/hosts

To be able to use for example https://myapp.local in our browser, we need to modify the /etc/hosts file on our local machine to point the custom domain name. The /etc/hosts file contains a mapping of IP addresses to URLs.

macOS and Linux

cd cli
./setup-hosts-file.sh

The helper script can both add or remove a entry from /etc/hosts. First enter the domain name, then press "a" for add, or "r" to remove. Follow the instructions on the screen.

Windows

Follow the instructions in ./cli/windows scripts/setup-hosts-file.txt

Install

docker-compose run composer create-project

Run

docker-compose up -d

-d is for detached mode, this will run containers in the background.

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:8080/ in your browser

MailHog

MailHog comes installed as a service in docker-compose.

๐Ÿš€ Open http://127.0.0.1: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

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


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.