Running WordPress multisite on Bedrock and Trellis: what the docs don’t tell you

Bedrock and Trellis both document multisite. Neither document is wrong. But the two of them together produce a handful of behaviours that are not in either set of docs, and every one of them looks like a bug the first time you meet it.

I run a six-site subdomain network on this stack. What follows is the list of things that cost me an afternoon each, with the code that causes them.

The configuration is the easy part

Bedrock's config/application.php is where the multisite constants live, and there is nothing surprising in them:

Config::define('WP_ALLOW_MULTISITE', true);
Config::define('MULTISITE', true);
Config::define('SUBDOMAIN_INSTALL', true);
Config::define('DOMAIN_CURRENT_SITE', env('DOMAIN_CURRENT_SITE'));
Config::define('PATH_CURRENT_SITE', env('PATH_CURRENT_SITE') ?: '/');
Config::define('SITE_ID_CURRENT_SITE', env('SITE_ID_CURRENT_SITE') ?: 1);
Config::define('BLOG_ID_CURRENT_SITE', env('BLOG_ID_CURRENT_SITE') ?: 1);
Config::define('NOBLOGREDIRECT', 'https://' . env('DOMAIN_CURRENT_SITE'));
Config::define('WP_CORE_DIRECTORY', env('WP_CORE_DIRECTORY') ?: false);Code language: PHP (php)

The one below it matters more than it looks:

Config::define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);Code language: PHP (php)

On a subdomain network each site is a different host, so a single shared cookie domain means a login cookie set on one subsite is presented to all of them. Setting it from HTTP_HOST scopes the cookie to the site that issued it. That is the behaviour you want, but it also means logging in to the network admin does not log you in everywhere, which surprises people who came from a subdirectory install.

The /wp trap, and why you must not "fix" it

This is the one that catches everybody, and it is worth understanding rather than memorising.

Bedrock puts WordPress core in a subdirectory, web/wp/. So siteurl — where the core files are — ends in /wp, while home — where the site appears to live — does not. On a single site you set both in .env and never think about it again:

WP_HOME='https://example.com'
WP_SITEURL="${WP_HOME}/wp"Code language: Bash (bash)

On multisite you cannot, because there is one .env and many sites, each with its own siteurl row in its own options table. Trellis's answer is a single variable:

    multisite:
      enabled: true
      subdomains: true
    env:
      wp_core_directory: wp # Pass the directory WP is installed in so that multisite URLs can be fixedCode language: YAML (yaml)

"Can be fixed" is doing a lot of work in that comment. What actually fixes them is an mu-plugin — Felix Arntz's site URL fixer, which Trellis's Bedrock template ships — that appends the core directory at runtime:

public static function fix_site_url( $value ) {
	$core_directory = self::get_directory();

	if ( substr( $value, - strlen( $core_directory ) - 1 ) !== '/' . $core_directory ) {
		$value .= '/' . $core_directory;
	}

	return $value;
}

if ( is_multisite() && defined( 'WP_CORE_DIRECTORY' ) && WP_CORE_DIRECTORY ) {
	add_filter( 'option_home', array( 'WPMS_Site_URL_Fixer', 'fix_home_url' ) );
	add_filter( 'option_siteurl', array( 'WPMS_Site_URL_Fixer', 'fix_site_url' ) );
	add_filter( 'network_site_url', array( 'WPMS_Site_URL_Fixer', 'fix_network_site_url' ), 10, 3 );
}Code language: PHP (php)

The consequence is that the value in the database is not the value WordPress uses, and the two standard ways of reading it disagree. Here are both, run against the same site a minute apart:

$ wp option get siteurl --url=https://www.craigpearson.test/
https://www.craigpearson.test/wp

$ wp db query "SELECT option_name, option_value FROM wp_4_options
               WHERE option_name IN ('siteurl','home')"
option_name	option_value
home	https://www.craigpearson.test
siteurl	https://www.craigpearson.testCode language: Shell Session (shell)

wp option get boots WordPress, so the filter runs and you see /wp. wp db query reads the row, so you see what is stored. Both are correct. Neither is a bug.

The failure mode is obvious once you have seen it: somebody notices that the stored siteurl "is missing /wp", writes the corrected value into the database, and now the filter appends a second one. Every admin asset 404s against /wp/wp/wp-admin/..., and the stored value looks more right than it did before.

So: on Bedrock multisite, never write siteurl by hand from a value you read through WordPress. If you must set it, set the bare value and let the filter do its job.

wp site create writes an http:// URL

Creating a subsite from the command line is two commands, not one, and the second one is not in the handbook:

wp site create --slug=NAME --title="Title" --email=admin@example.test

# wp site create writes an http:// URL -- switch it to https.
wp option update home    "https://NAME.example.test"    --url=http://NAME.example.test
wp option update siteurl "https://NAME.example.test/wp" --url=http://NAME.example.testCode language: Bash (bash)

Note the --url on the two updates uses http://, because that is still what the site is registered as at the moment you run them. And note that siteurl here does carry /wp: wp option update goes through WordPress, so it is being given the filtered form. This is the same asymmetry as above, and it is the reason it is worth understanding rather than copying.

Every WP-CLI command needs --url, and some need --user

On multisite, a command without --url silently targets the main site. Not an error — the main site. So a bulk update you believed ran across the network ran once, on blog 1, and reported success.

wp site list                                       # blog_id / url for every subsite
wp plugin list --url=https://shop.example.test
wp post list --post_type=product --url=https://shop.example.testCode language: Bash (bash)

The second half of this is --user. WP-CLI has no logged-in user by default, and wp_insert_post() drops tax_input entirely without one — silently, exit code 0. Anything touching taxonomies, terms or capabilities needs --user=1. The same applies to setting a block theme's style variation, where the wp_theme term is dropped for exactly this reason and the front end keeps the theme defaults while the resolver, in the same process, insists the variation is applied.

One nginx vhost serves the whole network

This is the part I expected to be hard and was not. Trellis generates a single vhost whose server_name already carries the wildcards:

server_name *.thatwp.test *.bouncycastles.pearsmith.test www.craigpearson.test
            bouncycastles.pearsmith.test *.shop.pearsmith.test *.craigpearson.test
            shop.pearsmith.test *.pearsmith.test thatwp.test pearsmith.test;Code language: Nginx (nginx)

Because the wildcard is in there, a new subdomain subsite needs no nginx change at all — no new vhost, no reload, nothing. That is genuinely nice, and it is not obvious from the config.

What it does not mean is that the subsite needs no Trellis change, and this is where I lost an afternoon. Trellis manages a block in /etc/hosts and regenerates it from site_hosts in group_vars on every trellis vm start. A subsite created with wp site create is not in site_hosts, so it works — nginx is happy to serve it — right up until the next VM start rewrites that block and drops the line. Then it resolves nowhere, and nothing about nginx or WordPress has changed.

Editing /etc/hosts by hand does not survive either, for the same reason. The only durable fix is to add the canonical host to site_hosts and restart the VM, even though nginx does not need it there:

    site_hosts:
    - canonical: pearsmith.test
      redirects:
      - www.pearsmith.test
    - canonical: www.craigpearson.test
      redirects:
      - craigpearson.test
    - canonical: shop.pearsmith.testCode language: YAML (yaml)

Deploys only carry part of the repository

Trellis deploys a subtree, not the repository. On this stack that is one line of configuration:

repo_subtree_path: siteCode language: YAML (yaml)

Everything above site/ — the Ansible roles, the group variables, the playbooks — is never copied to the server by a deploy. It reaches the server through a provision, which is a different command run at a different time.

The practical effect is that editing a value in group_vars and merging it changes nothing on the box, however convincing the diff looks. I have watched a change sit in main for a day while everyone involved believed it was live, because the deploy that followed it succeeded — it just had nothing to do with the file that changed.

Two habits fix it. Know which of your files are deploy-time and which are provision-time, and write it at the top of the README rather than in someone's memory. And check what is actually running rather than what you merged:

readlink /srv/www/example.com/currentCode language: Bash (bash)

That symlink is the only thing on the host that names the live release. Everything else — the branch, the last green pipeline, the last merge — is a statement about intent.

Local development: pass a working directory, do not cd

Local dev here runs in a Lima VM rather than Vagrant, with the site/ directory mounted read-write inside it. Commands go in over limactl shell, and there is one detail worth knowing before you write a script around it: a bare limactl shell reproduces the host's current working directory inside the guest. The host path does not exist there, so every call emits a cd failure on stderr before it runs anything:

$ limactl shell my-vm wp site list
bash: line 1: cd: /Users/me/code/project: No such file or directory
bash: line 1: cd: /Users/me: No such file or directory
blog_id	url
1	https://example.test/Code language: Shell Session (shell)

The output is correct. The two lines above it are not part of it, and they will end up in whatever you were capturing. Pass --workdir instead of cd-ing:

limactl shell --workdir /srv/www/example.com/current my-vm wp site listCode language: Bash (bash)

The same rule applies to any wrapper that prints its own banner before running your command. I have had a wrapper's Running command => ... line captured into published page content on this network more than once, because the capture looked clean in a terminal and only the diff showed the extra line.

What I would tell someone starting

  • Read siteurl through WordPress or through SQL, and know which you did. They differ by /wp and both are right.
  • Put --url in the command before you put anything else in it.
  • Add --user=1 by reflex for anything touching terms.
  • Add a new subsite to site_hosts even though nginx does not need it there.
  • Know which of your files a deploy carries and which need a provision, and write it down.
  • Never capture command output from a wrapper that prints its own line first.

None of this is a criticism of either project. Bedrock and Trellis are the reason a six-site network is a git clone and a provision rather than a weekend; the traps are the seams where two well-designed things meet.


More on how I work is on the About page, and the stack above is most of what is on my CV. If you have a multisite install that is behaving strangely, tell me about it.