I think (but i’m not sure) i should open this here. This could be a wp-cli related problem, anyway i’m unable to use wp-cli to manage a multisite + subfolders bedrock setup provisioned by Trellis.
vagrant@test /srv/www/test.develop.ment/current $ wp core version
4.3.1
vagrant@test /srv/www/test.develop.ment/current $ wp site list --debug
PHP Notice: Undefined index: HTTP_HOST in /srv/www/test.develop.ment/current/web/wp/wp-includes/ms-settings.php on line 30
PHP Stack trace:
PHP 1. {main}() /usr/bin/wp:0
PHP 2. include() /usr/bin/wp:4
PHP 3. include() phar:///usr/bin/wp/php/boot-phar.php:5
PHP 4. require() phar:///usr/bin/wp/php/wp-cli.php:26
PHP 5. require() phar:///usr/bin/wp/php/wp-settings-cli.php:114
Error: Site not found.
I became quite stuck with this, as I had a wp-cli file that was part of the repo I was using. I wrote these three rather messy functions that do a search and replace for all of the 3 different environments the wp-cli.yml file might be set to.
I created a new env var as well called mutlisite_site_name
- name: Replace live with current {{ site_env.mutlisite_site_name }}
command: sed -i 's/example.com/{{ site_env.mutlisite_site_name }}/g' wp-cli.yml
args:
chdir: "{{ deploy_helper.new_release_path }}/"
- name: Replace staging with current {{ site_env.mutlisite_site_name }}
command: sed -i 's/staging.example.com/{{ site_env.mutlisite_site_name }}/g' wp-cli.yml
args:
chdir: "{{ deploy_helper.new_release_path }}/"
- name: Replace development {{ site_env.mutlisite_site_name }}
command: sed -i 's/example.dev/{{ site_env.mutlisite_site_name }}/g' wp-cli.yml
args:
chdir: "{{ deploy_helper.new_release_path }}/"
Then in roles/deploy/defaults/main.yml I added that script
# Deploy hooks
# For list of hooks and explanation, see https://roots.io/trellis/docs/deploys/#hooks
deploy_build_before:
- "{{ playbook_dir }}/deploy-hooks/change-wp-cli-domain.yml"
- "{{ playbook_dir }}/deploy-hooks/build-before.yml"
As wp-cli.yml is part of the repo and setting up remote servers tried to use the url of my previously defined dev server, I searched for another solution.
I removed “url” from wp-cli.yml what caused wp-cli to use the fallback URL “example.com” as my DOMAIN_CURRENT_SITE is set to $_SERVER['HTTP_HOST']. The following fixes that and fallbacks to the .env value…
/**
* WP-CLI never reaches $_SERVER. Define DOMAIN_CURRENT_SITE as fallback to get wp-cli working
* @link https://make.wordpress.org/cli/handbook/common-issues/#php-notice-undefined-index-on-_server-superglobal
*/
if ( defined( 'WP_CLI' ) && WP_CLI && ! isset( $_SERVER['HTTP_HOST'] ) ) {
$_SERVER['HTTP_HOST'] = env('DOMAIN_CURRENT_SITE');
}
This does not work when setting up WordPress MultiSite via wp core multisite-install --title="site title" --admin_user="username" --admin_password="password" --admin_email="you@example.com"
and wp-cli fallbacks again to example.com. So the main domain needs to get set via the additional parameter --url="your_domain.com".
I’m wondering if there is a better option to make this working more safe also for other users such as getting url value in wp-cli.yml from the .env file.