DDEV and Craft CMS Quick-Start Guide

Migrating an Existing Craft CMS Project to DDEV

It's more likely your immediate usage of DDEV will be converting existing projects from bespoke local environments.

It’s more like­ly your imme­di­ate usage of DDEV will be con­vert­ing exist­ing projects from bespoke local envi­ron­ments – where every devel­op­er on your team is doing their own local set­up – to a local devel­op­ment envi­ron­ment that is uni­form across the team for the project, and dic­tat­ed by the project. 

Let’s look at how we can take an exist­ing Craft CMS project and rehome it in DDEV for local devel­op­ment. The end result will be a local­host devel­op­ment envi­ron­ment that can be stored in a con­fig file and saved as part of the project code­base (and be ver­sion con­trolled). Then any­one who comes behind me and uses this project, will only have to run git clone and then ddev start to get up and running. 

Craft Starter Blog

I’m going to rehome the Craft CMS Starter Blog project to use DDEV. The Starter Blog is an offi­cial repos­i­to­ry from the Craft CMS team that is the result of the tuto­r­i­al in the documentation.

I chose this because it doesn’t have any DDEV con­fig­u­ra­tion in it yet and it’s an exist­ing project. My copy of the project already has a data­base, of which I have an export so I can import it.

I already have the project repos­i­to­ry cloned local­ly and ready for a local devel­op­ment envi­ron­ment. I also have a data­base export wait­ing in the wings. 

I also already have DDEV installed and working.

The next step is to con­fig­ure the project with DDEV.

Inside the project direc­to­ry, we run ddev config just like we would for a new project. But this time we’re not start a new project, we’ll set­ting up an exist­ing one.

cd starter-blog/
ddev config --project-type=craftcms

Let’s start up the DDEV con­tain­ers for this project and then update our project to sup­port DDEV.

ddev start

Since I just cloned this repos­i­to­ry, I need to down­load the Com­pos­er depen­den­cy pack­ages. To do that, we’ll use the composer sub­com­mand in DDEV:

ddev composer install

Next, we need to import our data­base. Out-of-the-box, DDEV sup­ports Table­Plus, a very nice data­base man­age­ment app. It is a paid app but I use it so much that it has more than paid for the license fee in time saved and usefulness. 

Run­ning the command

ddev tableplus

will open up the Table­Plus app, if it’s installed, and con­nect to the data­base for the DDEV project you’re cur­rent­ly work­ing in. Pret­ty neat, right?

From here we can eas­i­ly import a data­base SQL file into our project.

We can also use the DDEV com­mand import-db to import the data­base export into our project.

ddev import-db

It will prompt us for the path of the data­base file we want to import, and then import the database.

Provide the path to the database you wish to import.
Pull path: /Users/ryan/Desktop/craft-blog.sql
 193KiB 0:00:00 [ 795KiB/s] [=========================>] 100%
Project type has no settings paths configured, so not creating settings file.
Successfully imported database 'db' for starter-blog
Existing database 'db' was dropped before importing

And now we’re all set with a project on DDEV! The next step would be to com­mit the .ddev hid­den direc­to­ry to our Git repos­i­to­ry and push it up to the remote repos­i­to­ry. You def­i­nite­ly do not want to ignore that direc­to­ry if you plan to get the full ben­e­fit of DDEV.

DDEV and Craft CMS Quick-Start Guide is made up of the following videos: