From 02c569455013fb18b6540d7fb72e980326661a54 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Wed, 2 Jan 2019 11:10:32 +0100 Subject: [PATCH] first commit --- .env.sample | 73 ++++++++++++++++ .gitignore | 1 + LICENSE | 21 +++++ README.md | 213 +++++++++++++++++++++++++++++++++++++++++++++ conf.d/php.ini | 5 ++ docker-compose.yml | 51 +++++++++++ wp-cli-test.sh | 7 ++ wp.sh | 4 + 8 files changed, 375 insertions(+) create mode 100644 .env.sample create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 conf.d/php.ini create mode 100644 docker-compose.yml create mode 100755 wp-cli-test.sh create mode 100755 wp.sh diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..07a9ba3 --- /dev/null +++ b/.env.sample @@ -0,0 +1,73 @@ +# .env file to set up your wordpress site + +# +# Network name +# +# Your container app must use a network conencted to your webproxy +# https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion +# +NETWORK=webproxy + +# +# Database Container configuration +# We recommend MySQL or MariaDB - please update docker-compose file if needed. +# +CONTAINER_DB_NAME=db + +# Path to store your database +#DB_PATH=/path/to/your/local/database/folder +DB_PATH=./../data/db + +# Root password for your database +MYSQL_ROOT_PASSWORD=root_password + +# Database name, user and password for your wordpress +MYSQL_DATABASE=database_name +MYSQL_USER=user_name +MYSQL_PASSWORD=user_password + +# +# Wordpress Container configuration +# +CONTAINER_WP_NAME=wordpress + +# Max Log File Size +LOGGING_OPTIONS_MAX_SIZE=200k + +# Path to store your wordpress files +#WP_CORE=/path/to/your/wordpress/core/files +#WP_CONTENT=/path/to/your/wordpress/wp-content +WP_CORE=./../data/site/wordpress-core +WP_CONTENT=./../data/site/wp-content + +# Table prefix +WORDPRESS_TABLE_PREFIX=wp_ + +# Your domain (or domains) +DOMAINS=domain.com,www.domain.com + +# Your email for Let's Encrypt register +LETSENCRYPT_EMAIL=your_email@domain.com + +# +# Backup location +# +# This option should be used when backing up using the script in the repo: +# https://github.com/evertramos/docker-wordpress-backup +#BACKUP_PATH_NAME=/backup + +# +# Crontab Rules +# +# Please only enable that if you know what you are doing, please refer to these samples: +# +# https://crontab.guru/examples.html +# +# And test if your setting is working +# +# Here is a basic rule for backup everyday at 04 am from monday to friday as of: +# +# https://crontab.guru/#00_04_*_*_1-5 +# +#BACKUP_CRONTAB_RULE="00 04 * * 1-5" + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..54376ba --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Evert Ramos + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d9c6fe --- /dev/null +++ b/README.md @@ -0,0 +1,213 @@ +# Using Wordpress with SSL enabled integrated with NGINX proxy and autorenew LetsEncrypt certificates + +![wordpress-docker-letsencrypt](https://github.com/evertramos/images/raw/master/wordpress.jpg) + +This docker-compose should be used with WebProxy (the NGINX Proxy): + +[https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion) + + +## Usage + +After everything is settle, and you have your three containers running (_proxy, generator and letsencrypt_) you do the following: + +1. Clone this repository: + +```bash +git clone https://github.com/evertramos/docker-wordpress-letsencrypt.git +``` + +Or just copy the content of `docker-compose.yml` and the `Dockerfile`, as of below: + +```bash +version: '3' + +services: + db: + container_name: ${CONTAINER_DB_NAME} + image: mariadb:latest + restart: unless-stopped + volumes: + - ${DB_PATH}:/var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + + wordpress: + depends_on: + - db + container_name: ${CONTAINER_WP_NAME} + image: wordpress:latest + restart: unless-stopped + volumes: + - ${WP_CORE}:/var/www/html + - ${WP_CONTENT}:/var/www/html/wp-content + environment: + WORDPRESS_DB_HOST: ${CONTAINER_DB_NAME}:3306 + WORDPRESS_DB_NAME: ${MYSQL_DATABASE} + WORDPRESS_DB_USER: ${MYSQL_USER} + WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD} + WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX} + VIRTUAL_HOST: ${DOMAINS} + LETSENCRYPT_HOST: ${DOMAINS} + LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL} + +# wpcli: +# image: tatemz/wp-cli +# volumes: +# - ${WP_CORE}:/var/www/html +# - ${WP_CONTENT}:/var/www/html/wp-content +# depends_on: +# - db +# entrypoint: wp + +networks: + default: + external: + name: ${NETWORK} +``` + +> **[IMPORTANT]** Make sure to update your **services** name for each application so it does not conflicts with another service, such as, in the _docker_compose.yml_ where we have **db** you could use **site1-db**, and **wordpress** you could use **site1-wordpress**. Update this to site2 when you put up a new site. + +2. Make a copy of our .env.sample and rename it to .env: + +Update this file with your preferences. + +```bash +# .env file to set up your wordpress site + +# +# Network name +# +# Your container app must use a network conencted to your webproxy +# https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion +# +NETWORK=webproxy + +# +# Database Container configuration +# We recommend MySQL or MariaDB - please update docker-compose file if needed. +# +CONTAINER_DB_NAME=db + +# Path to store your database +DB_PATH=/path/to/your/local/database/folder + +# Root password for your database +MYSQL_ROOT_PASSWORD=root_password + +# Database name, user and password for your wordpress +MYSQL_DATABASE=database_name +MYSQL_USER=user_name +MYSQL_PASSWORD=user_password + +# +# Wordpress Container configuration +# +CONTAINER_WP_NAME=wordpress + +# Path to store your wordpress files +WP_CORE=/path/to/your/wordpress/core/files +WP_CONTENT=/path/to/your/wordpress/wp-content + +# Table prefix +WORDPRESS_TABLE_PREFIX=wp_ + +# Your domain (or domains) +DOMAINS=domain.com,www.domain.com + +# Your email for Let's Encrypt register +LETSENCRYPT_EMAIL=your_email@domain.com +``` + +>This container must use a network connected to your webproxy or the same network of your webproxy. + +3. Start your project + +```bash +docker-compose up -d +``` + +**Be patient** - when you first run a container to get new certificates, it may take a few minutes. + +---- + +### Make sure the wordpress data files has user and group set to **www-data**, so you could update, install, delete files from your admin panel. + +---- + + +## WebProxy + +[WebProxy - docker-compose-letsencrypt-nginx-proxy-companion](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion) + +---- + +# Further Options + +## wp-cli (https://wp-cli.org/) + +For whoever uses *wp-cli* here is how to implement it on this repo. + + +i. Take down your services + +```bash +docker-compose down +``` + +ii. Uncomment the following lines on _docker-compose.yml_: + +```bash +# wpcli: +# image: tatemz/wp-cli +# volumes: +# - ${WP_CORE}:/var/www/html +# - ${WP_CONTENT}:/var/www/html/wp-content +# depends_on: +# - db +# entrypoint: wp +``` + +iii. Start your services again + +```bash +docker-compose up -d +``` + +iv. Test to see if it´s working + +```bash +./wp-cli-test.sh + +``` + +If you would, add the alias "wp" to your `.bash_aliases`: + +```bash +alias wp="docker-compose run --rm wpcli" +``` + +Next time you need to run a wp-cli command just go to where you have your docker-compose file and run a `wp` command. + +---- + +## Backup Option + +We developed a backup option for this set up which you can find more details here: + +[Docker Wordpress Backup](https://github.com/evertramos/docker-wordpress-backup) + + +## Issues + +Please be advised that if are running docker on azure servers you must mount your database in your disks partitions (example: `/mnt/data/`) so your db container can work. This is a some kind of issue regarding Hyper-V sharing drivers... not really sure why. + + +## Full Source + +1. [@jwilder](https://github.com/jwilder/nginx-proxy) +2. [@jwilder](https://github.com/jwilder/docker-gen) +3. [@JrCs](https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion). diff --git a/conf.d/php.ini b/conf.d/php.ini new file mode 100644 index 0000000..7fc73c5 --- /dev/null +++ b/conf.d/php.ini @@ -0,0 +1,5 @@ +file_uploads = On +memory_limit = 64M +upload_max_filesize = 64M +post_max_size = 64M +max_execution_time = 600 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9a144de --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +version: '3' + +services: + db: + container_name: ${CONTAINER_DB_NAME} + image: mariadb:latest + restart: unless-stopped + volumes: + - ${DB_PATH}:/var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + + wordpress: + depends_on: + - db + container_name: ${CONTAINER_WP_NAME} + image: wordpress:latest + restart: unless-stopped + volumes: + - ${WP_CORE}:/var/www/html + - ${WP_CONTENT}:/var/www/html/wp-content + - ./conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini + environment: + WORDPRESS_DB_HOST: ${CONTAINER_DB_NAME}:3306 + WORDPRESS_DB_NAME: ${MYSQL_DATABASE} + WORDPRESS_DB_USER: ${MYSQL_USER} + WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD} + WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX} + VIRTUAL_HOST: ${DOMAINS} + LETSENCRYPT_HOST: ${DOMAINS} + LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL} + logging: + options: + max-size: ${LOGGING_OPTIONS_MAX_SIZE:-200k} + +# wpcli: +# image: tatemz/wp-cli +# volumes: +# - ${WP_CORE}:/var/www/html +# - ${WP_CONTENT}:/var/www/html/wp-content +# depends_on: +# - db +# entrypoint: wp + +networks: + default: + external: + name: ${NETWORK} diff --git a/wp-cli-test.sh b/wp-cli-test.sh new file mode 100755 index 0000000..5bd1f1c --- /dev/null +++ b/wp-cli-test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +alias wp="docker-compose run --rm wpcli" + +wp --info + +exit 0 diff --git a/wp.sh b/wp.sh new file mode 100755 index 0000000..b4e35e1 --- /dev/null +++ b/wp.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +docker-compose run --rm wpcli +