This is a Docker based local development environment for WordPress. It is designed to be used with a production site. It contains a docker image - virtual environment to run Wordpress installation the same way on all computers. It also contains an assortment of scripts that can be ran in this virtual environment. These tools help to keep your WordPress instalation in GIT.
This repository runs the site on your local computer. You will be able to develop site without internet - and what is more important - without a risk of breaking production.
All the files you should concern yourself about are in ./wp-content
. There is a most recent Database dump in ./db-dump/production-dump.sql
.
- Make sure you have Docker toolbox for windows (important: select 'install git for windows' during installation. You will need GIT as well) or Docker for mac installed.
- After docker installation restart computer please.
- Windows only: Docker installs "Oracle VM Virtualbox Manager". Open it,
- Go to Settings->Network->Advanced->Port Forwarding
- Set up a rule with Host IP 127.0.0.1, Host port 80 and guest port 80
- Image here
- if "default" image is running, stop it and start it
- Open "Docker quickstart terminal" on Win or Terminal.app on mac.
- Set up your SSH Github, Bitbucket. Add keys to your account where this repository is.
- Navigate to where you want to have your project on disk using
cd
command. Example:cd /c/Users/artpi/Desktop/project
in case of windows and "Docker quickstart terminal" git clone https://github.com/artpi/wp-local-docker
cd wp-local-docker
docker-compose up -d
- Set up databases and WordPress
- Enter the container:
docker-compose exec --user www-data phpfpm bash
- Set everything up:
/var/scripts/setup.sh
- Enter the container:
- Once everything is set up, you can see the site under http://localhost
If you have a multisite, the short tutorial is:
docker-compose up
docker-compose exec --user www-data phpfpm /var/scripts/setup.sh
- Now you have to edit wordpress/wp-config.php
// This is assuming you have your whole network under `artpi.pl`
define( 'WP_ALLOW_MULTISITE', true );
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', true );
$base = '/';
define( 'PRODUCTION_DOMAIN_CURRENT_SITE', 'artpi.pl' );
define( 'DOMAIN_CURRENT_SITE', 'dev.local' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
- Add
127.0.0.1 dev.local
and127.0.0.1 subdomain.dev.local
for every subdomain in/etc/hosts
- Now run
docker-compose exec --user www-data phpfpm /var/scripts/import-db-from-prod-dump.sh
to set up everything. - You are good.
There are some scripts in bin/docker directory. To run them, you have to enter the virtual machine command line:
docker-compose exec --user www-data phpfpm bash
And then you can just run them /var/scripts/scriptname
.
This container has a script to rebase your content to mirror production server of your site. WordPress modifies stuff locally, so you will have to rebase it from time to time.
- Download db dump from production PHPMyAdmin and save in
./db-dump/production-dump.sql
- Commit that file to GIT
- Copy
./bin/docker/default-config.sh
to./bin/docker/config.sh
. Change variables. - Run
/var/scripts/rebase.sh
inside container. It will download all files from ftp that are different than your wp-content dir and delete the ones that are deleted. - Commit that as a rebase
- Profit.
We've bundled a simple administrative override file to aid in local development where appropriate. This file introduces both phpMyAdmin and phpMemcachedAdmin to the Docker network for local administration of the database and object cache, respectively.
You can run this atop a standard Docker installation by specifying both the standard and the override configuration when initializing the service:
docker-compose -f docker-compose.yml -f admin-compose.yml up
The database tools can be accessed on port 8092.
The cache tools can be accessed on port 8093.
Adding a docker-compose.override.yml
file alongside the docker-compose.yml
file, with contents similar to
the following, allows you to change the domain associated with the cluster while retaining the ability to pull in changes from the repo.
version: '3'
services:
phpfpm:
extra_hosts:
- "dashboard.localhost:172.18.0.1"
elasticsearch:
environment:
ES_JAVA_OPTS: "-Xms2g -Xmx2g"
Add this alias to ~/.bash_profile
to easily run WP-CLI command.
alias dcwp='docker-compose exec --user www-data phpfpm wp'
Instead of running a command like wp plugin install
you instead run dcwp plugin install
from anywhere inside the
<my-project-name>
directory, and it runs the command inside of the php container.
There is also a script in the /bin
directory that will allow you to execute WP CLI from the project directory directly: ./bin/wp plugin install
.
You can easily access the WordPress/PHP container with docker-compose exec
. Here's a simple alias to add to your ~/.bash_profile
:
alias dcbash='docker-compose exec --user root phpfpm bash'
This alias lets you run dcbash
to SSH into the PHP/WordPress container.
Alternatively, there is a script in the /bin
directory that allows you to SSH in to the environment from the project directory directly: ./bin/ssh
.
MailCatcher runs a simple local SMTP server which catches any message sent to it, and displays it in its built-in web interface. All emails sent by WordPress will be intercepted by MailCatcher. To view emails in the MailCatcher web interface, navigate to http://localhost:1080
in your web browser of choice.
This project is heavily modified fork of wp-local-docker