Trellis: separate application.php for single- & multisite on same host


I’d like to create a template for a server environment I can just throw away and easily build from scratch WITHOUT manually editing/uncommenting any configs in the process of rebuilding.
The repo should contain both multisite and singlesite Wordpress instances.

Is there any way to use separate application.php configs, when including both multisite & singlesite domains in wordpress_sites.yml (i.e. one with multisite: true AND another one with multisite: false)?

According to trellis’ documentation in order to configure trellis to install multisite-WP via wp-cli it’s necessary to include the accompanying “Config::” values.

/* Multisite */
Config::define('WP_ALLOW_MULTISITE', true);
Config::define('MULTISITE', true);
Config::define('SUBDOMAIN_INSTALL', false); // Set to true if using subdomains
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);

Whenever I provision my server, the playbook creates databases for both variants as told. Deploying also works as expected. But when installing via wp-cli (which I’d also like to automate) PHP throws errors on not finding the necessary multisite database entries.

WordPress database error Table 'development-single_wp_example_com_production.wp_blogs' doesn't exist for query SELECT  wp_blogs.blog_id FROM wp_blogs  WHERE domain = '' AND path = '/'  ORDER BY wp_blogs.blog_id ASC LIMIT 1 made by include('phar:///usr/bin/wp/php/boot-phar.php'), include('phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php'), WP_CLI\bootstrap, WP_CLI\Bootstrap\LaunchRunner->process, WP_CLI\Runner->start, WP_CLI\Runner->load_wordpress, require('wp-settings.php'), require('wp-includes/ms-settings.php'), ms_load_current_site_and_network, get_site_by_path, get_sites, WP_Site_Query->query, WP_Site_Query->get_sites, WP_Site_Query->get_site_ids

I guess I could just tell ansible to check if multisite is set false . Then uncommenting the multisite related lines in wp-config/application.php via hooks. But I was wondering if there was a cleaner way.


Just figured out a way myself :laughing: :person_facepalming: .


      enabled: false
      allow_multisite: false
      multisite: false
      subdomain_install: false


/* Multisite */
define('MULTISITE', env('MULTISITE'));
define('SUBDOMAIN_INSTALL', env('SUBDOMAIN_INSTALL')); // Set to true if using subdomains
1 Like