Perfect WordPress Development Environment

WordPress Development Problem

Anybody who has developed for php applications knows it can be tricky to have  the right environmental setup to do development work. I love WordPress, but it is no exception, until now . . . I found the fastest way to have a development environment for WordPress that can be blown away and brought up within seconds. The solution is to use Docker. I won’t go into detail in this article about how awesome docker is, but you should definitely check it out. This makes iterating new themes and plugins for WordPress simple and no need for having a separate computer with all the hosting configured.

Use Docker

We can bring up two separate containers. One image is the supported WordPress docker image and the second is the supported MySQL image. You tie the two together using docker compose. The key to make this work so well is we mount a drive from our local machine to a path in the docker image. This allows us to have a git repo with our plugin so we can do active development. When you are satisfied with the plugin or theme you can simply zip up the files you need using whatever automation you prefer and ship the code. You can start developing within 15 minutes. There is no need to set up a server with apache and mysql just to do development work.

docker-compose.yml

web:
    image: wordpress
    links:
     - mysql
    environment:
     - WORDPRESS_DB_PASSWORD=password
    ports:
     - "0.0.0.0:8080:80"
    volumes:
     - /Users/zaphinath/Projects/wordpressPlugins:/var/www/html/wp-content/plugins
mysql:
    image: mysql:5.7
    environment:
     - MYSQL_ROOT_PASSWORD=password
     - MYSQL_DATABASE=wordpress

Just copy this file, change the directory underneath volumes, and run docker-compose up to start the two docker containers. You can then browse to the IP of the WordPress docker container and viola – you are able to start developing. NOTE: On a Mac you will need to use docker-machine ip default to get the virtual machine’s IP address and then go to the right port in a web browser to view your WordPress install. Being able to get up and running fast and iterate over a clean WordPress install makes this the perfect WordPress development environment.

Leave a Reply