Get Started with DDEV: Local Development Made Easy
DDEV is a game-changer for local web development, especially for those working with PHP, Node.js, or even Python (experimentally). It leverages Docker containers to create isolated development environments in minutes, eliminating tedious configuration and setup hassles.
This guide will walk you through installing DDEV and setting up your first project, getting you coding in a flash!
Prerequisites
Before diving in, ensure you have the following:
- Docker: Download and install Docker Desktop for your operating system (Windows, Mac, or Linux) from https://docs.docker.com/get-docker/, or take a look at OrbStack (we at DeployHQ prefer this last one).
- Git: Install Git for version control. You can find download options for your system on https://git-scm.com/downloads.
- Code Editor or IDE: Choose your preferred code editor or IDE (e.g., VS Code, Sublime Text, PHPStorm) for development.
Installation
Homebrew
Homebrew is the easiest and most reliable way to install and upgrade DDEV:
# Install DDEV
brew install ddev/ddev/ddev
# One-time initialization of mkcert
mkcert -install
Install Script
The install script is another option. It downloads, verifies, and sets up the ddev
executable:
# Download and run the install script
curl -fsSL https://ddev.com/install.sh | bash
Setting Up Your First Project
- Create a New Project Directory: Open your terminal and navigate to your desired project directory. Run:
mkdir my-project && cd my-project
- Initialize a Git Repository:
git init
- Start a DDEV Project: Run the following command, replacing
<IMAGE>
with the appropriate image for your project (e.g.,php:8.1-apache
,node:18-alpine
):
ddev config --provider default --webserver apache --php 8.1 --mariadb 10.5 --storage-type local . <IMAGE>
This command creates a DDEV configuration file (.ddev.yaml
) in your project directory, specifying the web server, PHP version, database, and storage type.
- Start the Development Environment: Now, fire up the environment:
ddev start
DDEV will pull the specified Docker image, configure the environment, and display success messages with URLs to access your project in the browser (usually http://my-project.ddev.site
).
Code Example:
Let's assume you're working on a simple PHP project. Create a file named index.php
in your project directory with the following code:
<?php
echo "Hello, world from DDEV!";
Open http://my-project.ddev.site
in your browser, and you should see "Hello, world from DDEV!" displayed.
Additional Notes
DDEV Commands: Refer to the DDEV documentation for a complete list of commands (https://ddev.readthedocs.io/en/stable/users/usage/commands/):
-
ddev stop
: Stop the running environment. -
ddev ps
: See running containers. -
ddev exec
: Execute commands within the container. -
ddev ssh
: Access the container shell.
-
DDEV for CMS: DDEV offers pre-configured images for popular CMS systems like Drupal, WordPress, and Laravel. Explore the documentation for more information: https://ddev.com/blog/ddev-local-for-laravel-teams/.
Sharing Your Project: Easily share your development environment with collaborators using
ddev share
.
By now, you should have a basic understanding of DDEV and how to use it for local development. DDEV streamlines your workflow by providing consistent, isolated environments, allowing you to focus on building amazing things!
Further Resources:
- DDEV Documentation: https://ddev.readthedocs.io/
- DDEV GitHub Repository: https://github.com/pvtl/docker-dev
This guide provides a starting point for your DDEV journey. As you delve deeper, explore the extensive features and customizations DDEV offers to optimize your local development experience.