Local development with Bedrock

This how-to will guide you through creating a Bedrock WordPress project, containerising it and running it locally using docker compose.

Why starting with Bedrock?

roots/bedrock offers a standard structure and allows you to work with composer, thus providing better dependency management and enabling some software engineering good practices. You can install/uninstall plugins and themes via composer, use it’s autoload functionality and other goodies.


Bootstrap the project

First let’s create a project via composer starting from roots/bedrock .

$ composer create-project roots/bedrock my-site
$ cd my-site

Then we need to install the Presslabs Stack must-use plugin for WordPress.

$ composer require presslabs/stack-mu-plugin

In order to use the external object cache, we need to place it into our WP_CONTENT_DIR/object-cache.php.

$ ln -sf mu-plugins/stack-mu-plugin/src/object-cache.php web/app/object-cache.php

Create the Dockerfile

Presslabs Stack provides a base image for building and developing WordPress sites using Bedrock. <code>quay.io/presslabs/wordpress-runtime:bedrock-build</code> is used as a builder image and is optimized for build speed. <code>quay.io/presslabs/wordpress-runtime:bedrock</code> it’s optimized for running Bedrock enabled sites.

The Dockerfile is as simple as:

FROM quay.io/presslabs/wordpress-runtime:bedrock-build as builder
FROM quay.io/presslabs/wordpress:bedrock
COPY --from=builder --chown=www-data:www-data /app /app

Run using docker-compose

This docker-compose.yaml is a good starting point for local development using docker.

version: '3.3'

       - db
       - memcached
     image: quay.io/presslabs/wordpress-runtime:bedrock
       - ./:/app
       - "8080:8080"
     restart: always
       DB_HOST: db:3306
       DB_USER: wordpress
       DB_PASSWORD: not-so-secure
       DB_NAME: wordpress
       MEMCACHED_HOST: memcached:11211
       WP_HOME: http://localhost:8080
       WP_SITEURL: http://localhost:8080/wp
       WP_ENV: development

     image: percona:5.7
       - db_data:/var/lib/mysql
     restart: always
       MYSQL_ROOT_PASSWORD: not-so-secure
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: not-so-secure

     image: memcached:1.5

    db_data: {}

To boot up WordPress and MySQL server run:

docker-compose up -d

Installing a plugin (optional)

To install a plugin you can just:

docker-compose run wordpress composer require wpackagist-plugin/debug-bar

This site should be available at http://localhost:8080.

What’s next

VIDEO Tutorial: Create a Bedrock WordPress project