Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.env
.idea/
*.pem
src/*
51 changes: 51 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## 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`.

### 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 `<localuser>` to the local user you're logged in under.

```bash
sudo setfacl -Rm "u:<localuser>:rwx,d:u:<localuser>:rwx" ./src
```

This command sets up your local user as someone that owns and can edit the files in addition to the Docker user
22 changes: 17 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -53,15 +63,17 @@ services:
wordpress:
depends_on:
- database
build:
context: .
dockerfile: ./wp/Dockerfile
container_name: ${CONTAINER_NAME}-wordpress
image: wordpress:6.5.2-fpm-alpine
restart: unless-stopped
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
Expand Down
1 change: 1 addition & 0 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# cp me to .env and define variables!
HOSTNAME=

CONTAINER_NAME=

Expand Down
1 change: 1 addition & 0 deletions wp/.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alias wp="wp --allow-root"
11 changes: 11 additions & 0 deletions wp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +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

COPY ./wp/.bashrc /root/.bashrc