Drupal 11 local multisite with DDEV
I know, I know, everyone loves Lando. but just in case you happen to be a non-conformist like me and need to set up D11 asap with DDEV, here's how:
initial setup
$ mkdir -p ~/projects/d11multi && cd ~/projects/d11multi
$ ddev config --project-type=drupal --docroot=web
$ ddev composer create drupal/recommended-project:^11
$ ddev composer require drush/drush drupal/admin_toolbar
$ ddev drush site:install --account-name=admin --account-pass=admin -y
$ ddev drush en admin_toolbar -y
these commands will create a dir for the multisite; config a new Drupal project in it with web as its docroot; define its project template and version; import two key modules (in my almost humble opinion); define admin credentials and install the website; and finally enable a quality-of-life feature from one of the required modules.
telling DDEV about your setup
create the following files:
.ddev/config.multisite.yaml
additional_hostnames:
- site-1
- site-2
hooks:
post-start:
- exec: mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS site_1; GRANT ALL ON site_1.* to 'db'@'%';"
service: db
- exec: mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS site_2; GRANT ALL ON site_2.* to 'db'@'%';"
service: db
web/sites/sites.php
$sites['site-1.ddev.site'] = 'site_1';
$sites['site-2.ddev.site'] = 'site_2';
these files let both DDEV and Drupal understand there are 2 extra domains for your multisite.
next, run the following commands:
$ mkdir web/sites/site_1 web/sites/site_2
$ cp web/sites/default/default.settings.php web/sites/site_1/settings.php
$ cp web/sites/default/default.settings.php web/sites/site_2/settings.php
for each settings.php file, config as follows:
$databases['default']['default'] = [
'database' => 'site_X',
'username' => 'db',
'password' => 'db',
'host' => 'db',
'port' => '3306',
'driver' => 'mysql',
'prefix' => '',
];
replacing X with either 1 or 2.
set up additional sites
finally, run the command:
$ ddev drush site:install standard --db-url=mysql://db:db@db/site_X --site-name="Site X" --account-name=admin --account-pass=admin -y --sites-subdir=site_X
replacing X with either 1 or 2.
start your project
run this command to start things up:
$ ddev start
then visit your new multisite environment at:
https://d11multi.ddev.site/
https://site-1.ddev.site/
https://site-2.ddev.site/
also, you can stop everything with:
$ ddev stop
and that's pretty much it. hope you found this guide useful. if you have any questions or comments, please don't hesitate to reach me. thanks for reading!