diff --git a/.gitignore b/.gitignore index a9ad188..93ff827 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .env .idea/ +*.pem +src/* diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..7a82991 --- /dev/null +++ b/Readme.md @@ -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 `` 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 diff --git a/docker-compose.yml b/docker-compose.yml index 4a14545..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: @@ -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 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= 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 new file mode 100644 index 0000000..85f727c --- /dev/null +++ b/wp/Dockerfile @@ -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