TLDR: After setting up WordPress MU Domain Mapping on local in the standard way, add the subsite’s desired top-level domains to your hosts file and modify the Nginx config for your main site to listen for those URLs. Then just edit the site and point the site URL to the desired top-level domain.
It’s not uncommon when a client has a network of sites running off of one Multisite install to use the WordPress MU Domain Mapping plugin in production to give each site its own top-level domain. Normally we can develop just fine on local using the subdirectory or subdomain multisite structure. However, there are some (rare) cases where we need to have domain mapping setup in our local development environments in order to debug some weird issue that can only be reproduced with domain mapping enabled, such as something related to site URLs. This document describes the steps to take to enable domain mapping in VVV, where each site in a multisite network will have its own top-level domain.
What we are aiming for is something like this:
http://multisite.dev/subsite1/ to be accessible at http://subsite1.dev
http://multisite.dev/subsite2/ to be accessible at http://subsite2.dev
http://multisite.dev/subsite3/ to be accessible at http://subsite3.dev
In most cases you’ll be working with a copy of the production site’s database, in which case you’ll just adjust the commands and examples given here to what is appropriate for your setup.
1. Installing WordPress MU Domain Mapping on the network
The following describes the standard procedure of setting up WordPress MU Domain Mapping, and is not specific to VVV. If you’ve already done this, skip ahead to section 2.
SSH into VVV and go to the site root directory
Install the WordPress MU Domain Mapping plugin
wp plugin install wordpress-mu-domain-mapping --activate-network
Copy sunrise.php to the wp-content directory
cp htdocs/wp-content/plugins/wordpress-mu-domain-mapping/sunrise.php htdocs/wp-content/
Edit your wp-config.php file and add this line:
define( 'SUNRISE', 'on' );
Add the VVV IP address to the Domain Mapping settings
Go to Settings > Domain Mapping and add
192.168.50.4 as the “Server IP Address” setting. If for some reason your VVV IP address is different use that instead.
2. Modify your VVV Install to work with Domain Mapping
We need to do two things to make domain mapping work in VVV: modify the Nginx config file of the main site to listen for the subsite domains, and add the mapped domains to your hosts file.
1) Still inside VVV, etc the Nginx configuration file for the main site. For example:
sudo vim /etc/nginx/custom-sites/multisite.conf
In the server_name directive, add each of the subsite domains in addition to the main domain, for example:
server_name multisite.dev subsite1.dev subsite2.dev subsite3.dev;
sudo service nginx restart
2) Back on your local machine, edit your hosts file (
/etc/hosts on Mac and Linux,
C:\Windows\System32\Drivers\etc\hosts on Windows)
Add an entry pointing each subsite domain to VVV’s IP address (192.168.50.4), for example:
192.168.50.4 subsite1.dev subsite2.dev subsite3.dev
3. Change your subsite’s URLs to the desired mapped domains
Finally, you can change the URLs of your subsites to their own top-level domain.