DDEV and Craft CMS Quick-Start Guide
How to set up a Craft multi-site installation with DDEV.
Multi-site local development with Craft CMS and DDEV isn’t challenging to manage. Because Craft handles all of the heavy liftings of routing the web requests to the correct site in the system, we only need to set up the proper local domains in the DDEV configuration for the project and ensure Craft has those assigned to the respective sites.
In the Craft CMS project (we’re still working with the Craft Starter Blog project), I have already created three additional sites in a site group. The sites are:
I also have variables in the .env
file for those site URLs:
And assigned those environment variables to the appropriate site:
I also created three template directories, one for each site, with an index.twig
file in each with the site name variable.
<h1>{{ siteName }}
This will help us confirm everything is working, once we are ready to test our new multi-site configuration in DDEV.
This is a typical Craft multi-site setup; it isn’t anything specific to how we work with DDEV. However, what follows is how we’ll set up DDEV to work with Craft multi-site.
By default, DDEV has one local hostname per project. But in order to setup multi-site locally, we need to create multiple hostnames all pointing at the same DDEV project.
To do this, we need to jump into the .ddev/config.yaml
file, which holds the project-specific configuration for DDEV. This config file is read each time you start or restart the DDEV project. The file is YAML, so formatting matters.
Let’s open the .ddev/config.yaml
file in our IDE and take a look.
Around line 9 you should see a key called additional_hostnames
with an empty list denoted by square brackets. This tells us that the value data type is going to be a list. In YAML, that’s a series of hyphens, indented under the key.
The additional_hostnames
key is where we will input all of the hostnames we need DDEV to create for this project. This will only be the first part of the domain (something-here.ddev.site
), not the entire domain. Keep that in mind while creating these on your own.
We’ll remove the []
and on a new line, add a hyphenated list of our hostnames:
additional_hostnames:
- "microsite-one"
- "microsite-two"
- "microsite-three"
Since DDEV only reads the configuration file upon start and restart, let’s restart DDEV so it can add the hostnames to our project.
ddev restart
And, we see something like this:
Restarted starter-blog
Your project can be reached at https://starter-blog.ddev.site https://microsite-one.ddev.site https://microsite-three.ddev.site https://microsite-two.ddev.site https://127.0.0.1:49696
The project now has the original starter-blog
hostname but also three new hostnames for our new microsites. Perfect!
One last thing to do so everything works is to add the new domains to our .env
file variables for each site.
SITE_URL="https://starter-blog.ddev.site"
MICROSITE_ONE="https://microsite-one.ddev.site"
MICROSITE_TWO="https://microsite-two.ddev.site"
MICROSITE_THREE="https://microsite-three.ddev.site"
Now, when we access each domain in the browser, it should show the correct site!
DDEV and Craft CMS Quick-Start Guide is made up of the following videos: