Seravo / wordpress

The WordPress project layout used by many of Seravo's customers, suitable also for local development with Vagrant and git deployment
https://seravo.com
GNU General Public License v3.0
100 stars 54 forks source link

Document usage with network (multisite) #81

Open k1sul1 opened 6 years ago

k1sul1 commented 6 years ago

Getting this to work with an existing network wasn't too hard. /etc/hosts mappings get handled properly with this config:

###
# Configuration for Vagrant
###
name: multisite
#production:
  # This is used to automatically fetch data from a staging/production environment
  #domain: example.seravo.com
  #ssh_port: 12345
  #url: https://example.seravo.com
development:
  # Domains are automatically mapped to Vagrant with /etc/hosts modifications
  domains:
    - multisite.local
    - site1.multisite.local
    - site2.multisite.local
  # If you want to use zeroconf (.local domains) in your network you can use this.
  #avahi: true

Adding these to the wp-config seems to be enough for WP to notice it's a network installation:

define( 'WP_ALLOW_MULTISITE', true );

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'multisite.local');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Then just create the machine with vagrant up, import the existing database if you have one and do search replaces; which is easy if there's only a single domain and no domain mapping:

wp search-replace multisite.com multisite.local --all-tables # subdomains don't need to change!

In the case of domain mapping this becomes a bit harder, but one could use wp site list --field=url to get a list of all sites and write a script accordingly. Like replace the tld (.fi) of each site with a .local.

But that isn't a perfect solution, so I'm proposing adding a replacements prop to the Vagrant config. That requires a tiny bit of manual work, but it's more flexible and easier.

name: multisite
...
development: 
  domains: 
   - multisite.local
   - site1.multisite.local
  replace:
    multisite.fi: multisite.local
    site1.multisite.local: site1.multisite.local

That would make it possible to handle cases with domain mapping nicely, and search-replace scripts could work automatically.

k1sul1 commented 6 years ago

In order to pull the production database I first have to run wp-pull-production-db, which breaks the installation.

I then have to run wp search-replace multisite.fi multisite.local --all-tables --url=http://multisite.fi followed by a wp cache flush.

I think that this is because the protocol is included in the replacement details, causing the replace to miss out on subdomains. Could the protocol be stripped entirely?

Define new and old siteurl for later search-replacing...
==> Production site URL: http://multisite.fi
==> Development site URL: http://multisite.local
==> This is a WordPress Network install.
Is the information above correct (yes/no)?
ottok commented 6 years ago

The protocol (or at least //) is there to differentiate URLs from other occurences (site name, text contents, email domains etc). Most of the time it is a good thing not to change the domain in any other places than actual URLs but maybe here such a selector is too restricting..

k1sul1 commented 6 years ago

It's probably not a problem as long as you only go with pulls, pushing to the production database could be a problem.

ottok commented 6 years ago

Related issue: https://github.com/Seravo/wp-palvelu-vagrant/issues/37 "wp-pull-production-db fails for WP Network sites"

ottok commented 5 years ago

This is kind of a duplicate of #74

ottok commented 5 years ago

The latest Vagrant box released on Monday has an improved wp-pull-production-db command that now handles the main site of a network. Subdomains in a subdomain network cannot yet be automated however. See https://seravo.com/docs/get-started/release-notes/ and https://seravo.com/docs/configuration/wordpress-network/#local-development-with-vagrant-and-wordpress-network

ottok commented 5 years ago

See also https://seravo.com/docs/configuration/wordpress-network/

l3ku commented 4 years ago

I think we should probably wait for the Docker WP bootstrapping to be finalized so that we won't add more features to Vagrantfile anymore. After that, we can add support for multisite development via a config.yml feature that will trigger a use-network command or something that adds the necessary wp-config.php values and does the DB search replacing. I don't think it would make sense to document this now into https://seravo.com/docs, because according to the comments above using a multisite still requires some manual tinkering.

l3ku commented 4 years ago

Was this already implemented in https://github.com/Seravo/docs/commit/c8a6b21b58766091070c0abcfe68bf4cb5598b2e or is there a need to extend the content of the commit?

ottok commented 4 years ago

Maybe some docs on how to add additional domains in config.yml and some mention that currently for the alternatives domains to work, they all need to be search-replaced from example.com to example.local, example.net to example-net.local etc. And that is currently not automated in any way, so all we offer is docs.