From d76e614dba7788231807bda988d2a1aa5727f013 Mon Sep 17 00:00:00 2001 From: Curtis McHale Date: Tue, 29 Oct 2024 10:05:09 -0700 Subject: [PATCH 1/8] added the hostname var --- env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/env.example b/env.example index a0b190a..ff7ed75 100644 --- a/env.example +++ b/env.example @@ -1,4 +1,5 @@ # cp me to .env and define variables! +HOSTNAME= CONTAINER_NAME= From b7d5384a3fd583a9db2941719980238f19a121f5 Mon Sep 17 00:00:00 2001 From: Curtis McHale Date: Tue, 29 Oct 2024 10:06:03 -0700 Subject: [PATCH 2/8] ignoring more files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a9ad188..93ff827 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .env .idea/ +*.pem +src/* From 251d54b2a452ff00f1d887332f0e677b0c16394d Mon Sep 17 00:00:00 2001 From: Curtis McHale Date: Tue, 29 Oct 2024 10:06:22 -0700 Subject: [PATCH 3/8] added written directions --- Readme.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Readme.md diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..f21e004 --- /dev/null +++ b/Readme.md @@ -0,0 +1,47 @@ +## Local WordPress Development + +For video tutorials on setup: + +- [Local WordPress Setup in Five Minutes](https://www.youtube.com/watch?v=gEceSAJI_3s) +- [Adding SSL support to your WordPress Docker Setup](https://www.youtube.com/watch?v=HH4s3x1PiA4) + +## Setup + +You will need [Docker Desktop](https://www.docker.com/products/docker-desktop/) and [mkcert](https://github.com/FiloSottile/mkcert) installed. + +Clone this repository to your local machine. + +`git clone git@github.com:wazooinc/local-wordpress-development.git` + +Copy the `env.example` file to `.env`. + +Fill in the variables to match something like below. + +```bash +HOSTNAME=host.docker.internal + +CONTAINER_NAME=my_app + +DATABASE_NAME=wordpress +DATABASE_USER=admin +DATABASE_PASSWORD=test +DATABASE_ROOT_PASSWORD=test +``` + +### Create certs + +`cd` into the `nginx` directory and run `mkcert --install` to finish the setup of `mkcert`. You should **not** have to run this command again. You will need to restart your browsers to get the new certificate recognized in the certificate store. + +`cd` into the `certs` directory and run `mkcert host.docker.internal` which should create two files called `host.docker.internal-key.pem` and `host.docker.internal.pem`. + +Now cd to your directory with `Dockerfile` in it and run `docker compose up --build` to build the image and bring it online. You should be able to access your site at `host.docker.internal` and see the WordPress install screen. If you want to keep the docker process running in the background (without terminal logging all files accessed) run `docker compose up --build -d`. + +## Linux Users + +You will have issues trying to edit the files in your `wp-content` directory to do any development. macOS and Windows have virtualisation layers that make this not a problem on those platforms. To fix this on linux you need to use the `setfacl` command changing `` to the local user you're logged in under. + +```bash +sudo setfacl -Rm "u::rwx,d:u::rwx" ./src +``` + +This command sets up your local user as someone that owns and can edit the files in addition to the Docker user From 968e2661eb25048a0d7482f2e218f64bc5c0660e Mon Sep 17 00:00:00 2001 From: Curtis McHale Date: Tue, 29 Oct 2024 10:15:02 -0700 Subject: [PATCH 4/8] adding phpmyadmin location to docs --- Readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Readme.md b/Readme.md index f21e004..7a82991 100644 --- a/Readme.md +++ b/Readme.md @@ -36,6 +36,10 @@ DATABASE_ROOT_PASSWORD=test Now cd to your directory with `Dockerfile` in it and run `docker compose up --build` to build the image and bring it online. You should be able to access your site at `host.docker.internal` and see the WordPress install screen. If you want to keep the docker process running in the background (without terminal logging all files accessed) run `docker compose up --build -d`. +### PHPMyAdmin + +This is available at `host.docker.internal:8081` with the `DATABASE_USER` and `DATABASE_PASSWORD` you set in your `.env` file + ## Linux Users You will have issues trying to edit the files in your `wp-content` directory to do any development. macOS and Windows have virtualisation layers that make this not a problem on those platforms. To fix this on linux you need to use the `setfacl` command changing `` to the local user you're logged in under. From e529528b5656f05b5cffc3ee2a19a3ee75b3b807 Mon Sep 17 00:00:00 2001 From: Curtis McHale Date: Tue, 29 Oct 2024 10:15:21 -0700 Subject: [PATCH 5/8] updating WP to latest version --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4a14545..6dd002d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,7 +54,7 @@ services: depends_on: - database container_name: ${CONTAINER_NAME}-wordpress - image: wordpress:6.5.2-fpm-alpine + image: wordpress:6.6.2-fpm-alpine restart: unless-stopped env_file: .env environment: From a7d30f009f05a536e8d59e894e991f9490ce5ce5 Mon Sep 17 00:00:00 2001 From: Curtis McHale Date: Tue, 29 Oct 2024 10:51:34 -0700 Subject: [PATCH 6/8] adding wp cli to the docker image --- docker-compose.yml | 4 +++- wp/Dockerfile | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 wp/Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index 6dd002d..10c834a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -53,8 +53,10 @@ services: wordpress: depends_on: - database + build: + context: . + dockerfile: ./wp/Dockerfile container_name: ${CONTAINER_NAME}-wordpress - image: wordpress:6.6.2-fpm-alpine restart: unless-stopped env_file: .env environment: diff --git a/wp/Dockerfile b/wp/Dockerfile new file mode 100644 index 0000000..b9b8eba --- /dev/null +++ b/wp/Dockerfile @@ -0,0 +1,10 @@ +FROM wordpress:6.6.2-fpm-alpine + +## Installing WP CLI +RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar +RUN chmod +x wp-cli.phar +RUN mv wp-cli.phar /usr/local/bin/wp + +## Bash +RUN apk add --no-cache bash + From 1cd35c785f07351bfc41e1e376f1b725b1901383 Mon Sep 17 00:00:00 2001 From: Curtis McHale Date: Tue, 29 Oct 2024 11:01:34 -0700 Subject: [PATCH 7/8] alias to always run wpcli as root --- wp/.bashrc | 1 + wp/Dockerfile | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 wp/.bashrc diff --git a/wp/.bashrc b/wp/.bashrc new file mode 100644 index 0000000..e538a4b --- /dev/null +++ b/wp/.bashrc @@ -0,0 +1 @@ +alias wp="wp --allow-root" diff --git a/wp/Dockerfile b/wp/Dockerfile index b9b8eba..85f727c 100644 --- a/wp/Dockerfile +++ b/wp/Dockerfile @@ -1,10 +1,11 @@ FROM wordpress:6.6.2-fpm-alpine +## Bash +RUN apk add --no-cache bash + ## Installing WP CLI RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar RUN chmod +x wp-cli.phar RUN mv wp-cli.phar /usr/local/bin/wp -## Bash -RUN apk add --no-cache bash - +COPY ./wp/.bashrc /root/.bashrc From 264506625c02f70b248e149460abf5991124ac5b Mon Sep 17 00:00:00 2001 From: Curtis McHale Date: Tue, 29 Oct 2024 11:01:45 -0700 Subject: [PATCH 8/8] spacing --- docker-compose.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 10c834a..f4d5d59 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,17 @@ services: MYSQL_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD} MYSQL_USER: ${DATABASE_USER} healthcheck: - test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost", "-u", "root", "-p$$DATABASE_ROOT_PASSWORD" ] + test: + [ + "CMD", + "mysqladmin", + "ping", + "-h", + "localhost", + "-u", + "root", + "-p$$DATABASE_ROOT_PASSWORD", + ] timeout: 20s retries: 10 ports: @@ -61,9 +71,9 @@ services: env_file: .env environment: WORDPRESS_DB_HOST: database:3306 # use the same name as database service - WORDPRESS_DB_NAME: '${DATABASE_NAME}' - WORDPRESS_DB_USER: '${DATABASE_USER}' - WORDPRESS_DB_PASSWORD: '${DATABASE_PASSWORD}' + WORDPRESS_DB_NAME: "${DATABASE_NAME}" + WORDPRESS_DB_USER: "${DATABASE_USER}" + WORDPRESS_DB_PASSWORD: "${DATABASE_PASSWORD}" volumes: - wordpress:/var/www/html - ./src:/var/www/html/wp-content:rw