Rapid dev environment using docker for modern WordPress development.
This project is experimental and is currently in "works on my machine" stage. i.e it is only tested in OSX Sierra 10.12.5. Please feel free to try and report any bug found. Pull requests, issues, and project recommendations are more than welcome!
WP Dev aims to setup dev environment for modern WordPress development using simple yaml configuration inside setups.yml
.
A basic setup will only have website name, host and database name. The build command will fetch latest WordPress, configure
and make it ready for you to work further. If git source
is provided, it will clone the project from given repo. The system
is also capable of provisioning database, installing plugins and themes using wp-cli
during project setup.
# Sample configuration
website1:
host: website1.dev
env:
DB_NAME: website1_db
- PHP-fpm 7.0.x
- Nginx (stable version)
- Supervisor
- MySQL 5.7.*
- Redis
- WP-CLI
- Composer
- phpMyAdmin & Adminer
-
Install docker: https://docs.docker.com/engine/installation/
-
Make sure that you have
docker-compose
installed$ docker-compose --version docker-compose version: 1.11.2
If not, install
docker-compose
: https://docs.docker.com/v1.11/compose/install/ -
Install shyaml: https://github.com/0k/shyaml#installation
-
Install
git
if you haven't already: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
Application level environment variables are located inside app_env
. Following values are configurable.
# WP Dev
export APP_NAME="wpdev"
export APP_PORT="80"
export NETWORK_NAME="wpdev_network"
export LOG_FILE="${PWD}/logs/${APP_NAME}.logs"
# Default WordPress Settings
export WP_DEFAULT_TITLE="WordPress" # Site title
export WP_ADMIN_USER="admin"
export WP_ADMIN_PASSWORD="admin"
export WP_ADMIN_EMAIL="[email protected]"
# MySQL Database
export MYSQL_PORT="3306"
export MYSQL_ROOT_PASSWORD="wpdev"
export DB_HOST="172.19.0.25"
export DB_USER="wpdev"
export DB_PASSWORD="wpdev"
export MYSQL_CLIENT_PORT="8080"
# Redis
export REDIS_PORT="6379"
# phpmyadmin or adminer
export MYSQL_CLIENT="phpmyadmin"
Copy or rename setups.template.yml
to setups.yml
to get started with the website setup. Website name, host and DB_NAME
inside env are the only values required. Website name can only be alphanumeric and can contain hyphen/dash (-).
# Basic setup
website1:
host: website1.dev
env:
DB_NAME: website1_db
# Complete entry with source as a git repo
website2:
host: website2.dev
source: [email protected]:user/project.git
title: "Website 2 with all settings"
admin_user: "admin"
admin_password: "admin"
admin_email: "[email protected]"
plugins:
- "plugin-slug-1 --activate"
- "plugin-slug-2"
themes:
- "theme-slug-1 --activate"
- "theme-slug-2"
env:
DB_NAME: website2_db
# WordPress 4.3
website3:
host: website3.dev
version: 4.3
env:
DB_NAME: website3_db
Option | Description | Default |
---|---|---|
host | Host name. This entry should also be made inside /etc/hosts |
|
source | Git source for the project to clone from | |
version | WordPress version | latest |
title | WordPress site title | defaults from app_env |
admin_user | WordPress admin user | defaults from app_env |
admin_password | WordPress admin password | defaults from app_env |
admin_email | WordPress admin email | defaults from app_env |
plugins | List of plugins to install during setup. You can provide all parameters that wp-cli accepts, eg: --activate or --debug |
|
themes | List of themes to install during setup. You can provide all parameters that wp-cli accepts, eg: --activate or --debug |
|
env | Environment variables like DB_NAME . DB_NAME is required. |
You only need to run build script if you have made any changes in setups.yml
file.
$ ./wpdev build
To build core images only, use
$ ./wpdev build core
# To skip cache, use --no-cache option
$ ./wpdev build core --no-cache
To build projects only, use
$ ./wpdev build projects "<list of website name from setups.yml>"
You can access help file using ./wpdev build -h
You can skip this step if you just build the projects using above step. The projects should already be up and running. From next time, you can just boot the containers using following command as the related project containers are already built.
$ ./wpdev up
Update /etc/hosts
by adding all hosts listed in setups.yml
0.0.0.0 your-project.host
If you followed above steps correctly then, at this point, you should be able access project in your browser. Project files are
located inside projects
folder.
Database configs are stored in environment variables. In order to use it in say your project, use getenv
.
/** The name of the database for WordPress */
define('DB_NAME', getenv('DB_NAME'));
/** MySQL database username */
define('DB_USER', getenv('DB_USER'));
/** MySQL database password */
define('DB_PASSWORD', getenv('DB_PASSWORD'));
/** MySQL hostname */
define('DB_HOST', getenv('DB_HOST'));
You can shutdown running containers using following script.
$ ./wpdev down
You can delete all related containers using destroy script.
$ ./wpdev destroy
Rebuild will first delete all related containers and builds it again. It is same as running ./wpdev destroy && ./wpdev build
.
$ ./wpdev rebuild -h
usage: rebuild
--no-cache Skip cache
-h | --help Display this help text
To override configurations for a project, copy core/configs/default
folder and name it to your website name you are
using in setups.yml
. You can now change required configurations for the project. The system will first check if the
configuration for the website is available and builds it, if not, it will use default configuration.
All volumes are mounted inside .data
folder except the logs. Logs are mounted inside logs
folder.
- Composer: .data/composer
- MySQL: .data/mysql
- Redis: .data/redis
- WP-CLI: .data/wp-cli
If you want to import database for a project during setup, just add a sql file with same name as your database name and the system
will automatically import it during the build process. So for the basic setup above in Configure websites
section, you need to add a file called website1_db
inside database folder.
To backup all databases, use
$ ./wpdev db backup_all
By default it will save backup to the database
folder. You can provide custom path using -p
option.
$ ./wpdev db backup_all -p /path/to/downloads/bkp.sql
To only backup some databases, use
$ ./wpdev db backup -d "db1 db2"
Same as above it will save backup to the database
folder. You can provide custom path using -p
option.
$ ./wpdev db backup -d "db1 db2" -p /path/to/downloads/bkp.sql
You can choose between phpmyadmin
or adminer
as your mysql client. By default the client runs on port 8080
.
These values are configurable in app_env
. So with default configuration, you can access the client by visiting
http://localhost:8080. You can use the values DB_USER
and DB_PASSWORD
from app_env
to login.
By default, mysql runs on ip 192.168.10.25
as listed in app_env
. So if you are using adminer as a client you should
use that ip as a host. To connect database using third party client like sequel pro, use 0.0.0.0
as a host.
- Add PHP_CodeSniffer for WordPress.
- Ability to sync/update plugins, themes, core etc for a project.
- Ability to create new project from existing one (variation).