Setting up PHP for local development

docker laravel php

PHP Dev Environments

TL;DR I run PHP projects in Docker in both development and production. I just mount the project code into the Docker machine while working locally. The Docker image always has the current main release as deployed.

Like many developers I frequently have to setup a new system with my development environment. I have spent a large amount of time finding development environments that work with me.

The Prebuilt Options:

These development environments have their pros and cons. XAMPP is fast to install but provides limited control and additional functionality. The Laravel provided solutions work well with many Laravel projects and may work with some other projects but have some compatibility issues and are restricted in how they operate.

Using Docker

My personal recommendation for local development environments for a PHP project is to dockerize the production environment into a Docker image as part of your repos container registry. This same environment can be used both locally and in production with the correct use of environment variables.

Projects I have lead on tend to have a docker-compose.yml file at the root of their project with a .docker/ directory with the associated templates for the machine images.

docker-compose.yml

version: '3.0'

services:
  web:
    # Apache/Nginx PHP

  mysql:
    # MySQL database

This article is a work in progress. Come back for updates.