Local environment for Acquia Site Factory
- Last updated
- 1 minute read
Goal
Set up a best practice local environment for an Acquia Site Factory platform.
Overview
The purpose of this tutorial is to explain how to set up a best practice local environment for Drupal multisite, including on Acquia Site Factory:
- Configure Lando to support wildcard DNS.
- In settings.php, set an "App ID" to use in code for a specific multisite in any environment.
- In settings.php, set database, public files, memcache prefix, Solr core, and other settings per "App ID".
- Configure Drush aliases per multisite and per environment.
- Write bash scripts to push and pull sites using these aliases.
-
Configure Lando with wildcard DNS
Lando is a docker orchestration framework for development environments.
There are alternatives to Lando like ddev or docksal, but my preference is Lando because:
- It's simple to configure with YAML.
- It supports many other services like memcache, solr, redis, elasticsearch, mssql, etc.
- It runs on Macs, Windows, or Linux
- Their homepage is fancy.
If you're unfamiliar with Lando, reference their documentation before continuing here.
Acquia supports a "Lando recipe" that configures a set of Docker services that resembles an Acquia Cloud environment with services for Apache / php-fpm, MySQL, memcache, and Solr. This recipe can be simply extended to support multisite, including multisite for Acquia Site Factory.
If you're using Cloud IDE, it does not support running multiple sites at once because it only has 1 hostname. It is possible to work around this with path based multisites, but we can cover that in a different tutorial if requested.
The below example shows:
- Lando configuration using Acquia recipe
- Wildcard DNS for any subdomain of *.client1.lndo.site
- Other useful tips
Copy this to the project root of your Site Factory platform and run: lando start
-
In settings.php, set an "App ID" to use in code for a specific multisite in any environment
It's very helpful to have an "App ID" or unique identifier per multisite:
- Used in Drush aliases per environment
- Used in settings.php for config overrides and settings
- Used in custom code if necessary
Add the below code to the top of settings.php to map an environment variable to this "App ID". If you're using Acquia Site Factory, ensure this settings.php is loaded from a post-settings-php factory hook.
The "App ID" is determined by the first piece of the hostname. This is the "site name" on Acquia Site Factory and is consistent between all environments, including in this Lando environment.
We'll use this environment variable in the next steps.
-
In settings.php, set database, public files, memcache prefix, Solr core, and other settings per "App ID"
Once your "App ID" is set, configure Lando resources per multisite. This sets the database name, public files directories, and memcache prefix to the "App ID".
If you need a Solr core per multisite, add these lines to your settings.php and .lando.yml:
settings.php
.lando.yml (create a core for each multisite)
-
Configure Drush aliases per multisite and per environment
Acquia provides Drush aliases per environment you can find at:
- The "Credentials" tab of your Acquia Cloud account
- Using "acli remote:aliases:download" on command line.
- Ensure Acquia application UUID is set in .acquia-cli.yml at project root with config key "cloud_app_uuid".
But these aliases are not per multisite. You can pass the multisite URL per environment in the --uri option to Drush commands, but certain commands like "sql:sync" don't support the URI option and require specific aliases. And it's a hassle.
As a best practice, modify your Drush aliases file to have an alias per multisite per environment. It's super helpful both for manual use on CLI to target specific sites and for use in bash scripts and automation.
If it's a small number of sites, it's reasonable to do manually. If it's a large number of sites, you can write a script to do it. The acquia/acsf-tools project provides a YAML file you can use in a script with all multisites.
The below example shows multisite aliases for App IDs "site1" and "site2" of application "client1". After saving this, discover Drush aliases with: drush sa
-
Write bash scripts to push and pull sites using these aliases
The below bash script shows how to use Drush aliases in multisite automation with environment and "App ID" passed as arguments.
Example usage would be something like: