Using a local dev environment is standard practice, and yet, getting a stack that is easy to set up and use is still a challenge. If you’re using a Mac, many tutorials recommend building the development environment natively, since Apache is bundled with macOS.
Adding a few elements seems easy, after all, a local development environment for PHP includes at minimum two things:
- A web server configured to compile and run your PHP scripts on the fly and serve them to your browser.
- A database server to pull data and render it in your PHP application.
However, that isn’t enough in most cases. You may also want to make it easier to manage and test your application, so you would also need:
- SSH access.
- An email catch-all.
- And what about local SSL support?
- Virtual hosts to easily access your works-in-progress in your browser.
To set these up, even for one site, you’re looking at some detailed configuration. If you were just managing ONE site, it wouldn’t be a problem. However, to make it easier to add and manage multiple sites, you might also want:
- A way to start and stop services.
- Some way to manage those databases, like PHPMyAdmin.
- Configuring specific versions of your PHP projects
- A way to manage custom environment variables.
And once you starting adding all of those packages to manage these, you need some way to manage them and keep them up to date. Oh... and what if you want to add new projects without repeating the same setup each time? This is why Docker containers have gotten more popular in the last few years.
Docker shows up well comparison to other options like VMs when it comes to lightweight local development. Docker containers are faster and they don’t consume a lot of resources. With Docker Compose, you can manage different packages and dependencies. For example, you can set up different PHP environments per project, or add services like Apache Solr.
The main issue with Docker? That is a lot to manage and maintain and takes considerable knowledge of Docker to set up. So! There have been many local development tools released which package up the tools you need, and make it work. One of these options is DDEV-Local, which is completely free and open source. It comes with everything you need to create local development and quickly deploy to production.
Here's a video tutorial showing you how to set up DDEV-Local from scratch on macOS. This gives you a complete PHP development environment with developer tools like:
- MySQL Client (mysql) – Command-line interface for interacting with MySQL.
- Composer – Dependency Manager for PHP.
- Drush – Command-line shell and Unix scripting interface for Drupal.
- WP-CLI – Command-line tools for managing WordPress installations.
- MailHog mail catcher for email capture and review.
Read more about the developer tools in the docs.
Need any help? Post your questions tagged with #ddev on Stack Overflow.