Pantheon Community

WP multisite, multidev environment setup flow

I have a multidev setup for a WP multisite.

Every time I create a new multidev environment I get a database connection error in that new environment because the URLs do not get updated from the cloned Dev environment to the new multidev environment.

I have created a custom workflow script (hooked into clone_database) to run passthru(‘wp search-replace…’) for each of the environments URLs. Every time I create a new multidev environment I must update this script with the new environment name and url, commit & merge that to Dev, then do another clone from the Dev environment to the new multidev environment which runs the custom workflow and updates the URLs in the database.

Please tell me I have been doing this inefficiently and there is an easier option.

@ataylorme do you have any insight in this area?
@carlalexander may also have some knowledge around multisite on Pantheon.

@Dan I’m reading this as you have the multidev environment name and URL hard-coded in your Quicksilver script.

Have you tried generating those dynamically from Pantheon environment variables?

$_ENV['PANTHEON_ENVIRONMENT'] will give you the name of the multidev environment, which can also be used in conjunction with $_ENV['PANTHEON_SITE_NAME'] to construct the multidev URL (e.g. 'https://' . $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $_ENV['PANTHEON_SITE_NAME'] . '').

1 Like

The domains are hard-coded in the Quicksilver script.

Excellent point on using the Pantheon environment variables.

Your solution would work if the multidev environments were always set up from a clone of Dev like my above example.

Unfortunately my example failed to mention that there are multiple teams and multiple developers creating environments, and they can be cloned from any of the other environments, not just the Dev environment.

Is there a way to get a dynamic list of all Pantheon environments?

Or maybe I am not fully understanding your solution. I am imagining a solution such as:

if( !empty( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {
    switch( $_ENV['PANTHEON_ENVIRONMENT'] ) {
        case 'live':
            passthru( 'wp search-replace "test-' . $_ENV['PANTHEON_SITE_NAME'] . '" "" --all-tables' );

        case 'test':
            passthru( 'wp search-replace "dev-' . $_ENV['PANTHEON_SITE_NAME'] . '" "test-' . $_ENV['PANTHEON_SITE_NAME'] . '" --all-tables' );

            foreach( all_environments as current_env ) {
                passthru( 'wp search-replace "current_env" "' . $_ENV['PANTHEON_ENVIRONMENT'] . '-' . $_ENV['PANTHEON_SITE_NAME'] . '" --all-tables' );

Unfortunately, there isn’t a way from inside a Quicksilver script. You could do the replacement with wp-cli via Terminus but it would be a manual process, assuming your multidev creation is also manual. In that case, the dev who creates the multidev can do terminus wp site.env -- search-replace

If you are creating multidevs through an automated process, such as continuous integration, you could run the search and replace via Terminus after multidev creation, which would also be via Terminus.

Hi @Dan,

Have you tried Migrate DB Pro CLI addon? I think this would work for your needs.

The CLI addon for Migrate DB Pro could help with this. You can just use the pull command in your CLI script. The add on can detect the URL and path automatically. In theory, this should work. I have not tested this.

Here’s a link to the docs for the Pull command.

You’ll have to store the Migrate DB Pro secret key, possibly in a pantheon hidden directory or just as a constant in wp-config.php while your testing your script.

Link to CLI docs

Hi @Dan,

It looks like you can use the after stage in the create_cloud_development_environment Quicksilver workflow to trigger the Migrate DB Pro pull command. The multidev site should be ready to go at that point.

That’s when you would run your wp-cli command to pull the DB from whatever environment you want. You can also setup preconfigured profiles. wp migratedb pull ...

With the multisite add on you can migrate subsites to another multisite.

wp migratedb <push|pull> <url> <secret-key>
  [--find=<strings>] [--replace=<strings>]
  [--include-tables=<tables>] [--exclude-post-types=<post-types>]
  [--skip-replace-guids] [--exclude-spam] [--preserve-active-plugins]