Paul Redmond has written up a tutorial sharing his simple approach to using Docker and PHP to provide a more robust development environment.
Getting started with Docker and PHP can still be a steep learning curve. You might feel that you don’t need something like Docker and that Vagrant or full local development work just fine. I still use local development on some projects because the barrier to entry is small.
You will likely face scenarios where you require different versions of PHP, work with multiple developers, and seek consistency between environments. When you’re working with a team, you need a consistent way to develop. I’ve been on teams where different versions of PHP and MySQL varied between developers. I want to show you how Docker can fill the gap of providing consistent development environments, and do so without a huge amount of added complexity.
He starts with some background on why he decided to learn how to use Docker for his PHP development and how it has helped simplify his setup. He then walks you through some of his initial steps with Docker, providing the commands to create a new Laravel project and the structure he uses for his projects and the base image. He covers the contents of the Dockerfile, the Apache VirtualHost setup and how to build out the image. The post also includes instructions for:
- running Apache
- running "docker compose"
- adding a volume for local development
- adding MySQL
- running commands
- how to connect to the MySQL instance running in the container
Each item on the list includes configuration changes and commands that you'll need to get everything set up and running in a simple Docker container on your system.