Paulund
2019-10-20 #wordpress

Easiest WordPress Development Setup

In this tutorial we're going to investigate what is the quickiest and easiest way of getting a WordPress site up and running for development.

In the past in order to have a WordPress development site you would need to install Apache/Nginx, MySQL and PHP and having these running on your local machine before you can even install WordPress.

The easiest way of getting WordPress running locally is by using docker-compose. This allows you to have a development site running in seconds.

There is a docker image that will install the latest version of WordPress within an container, which means you don't even have to download the latest version of WordPress. You just spin up the docker container and you have everything you need to get the site running.

Using docker compose means we can also have a database running to install the WordPress site in seconds.

Start a new project in your IDE and create a docker-compose.yml file and add the following.

version: '3.3'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    volumes:
      - ./wp-content/themes:/var/www/html/wp-content/themes/
      - ./wp-content/plugins:/var/www/html/wp-content/plugins/
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DEBUG: 1
volumes:
  db_data: {}

Then you can create the wp-content folder in the root of your project with a themes and plugins folder inside.

By assigning these folders to volumes on your WordPress image you can create new plugins and themes and they will go into the docker container to be used by WordPress.

    volumes:
    - ./wp-content/themes:/var/www/html/wp-content/themes/
    - ./wp-content/plugins:/var/www/html/wp-content/plugins/

Run docker-compose up -d and your local WordPress environment will be available at http://localhost:8000.