WordPress Multisite Domain Mapping with Trellis

Below is a walkthrough on how we are currently managing the addition of a TLD to a WordPress Multisite subsite. If someone can let me know of an easier way to manage this using:
https://premium.wpmudev.org/project/domain-mapping/ or https://wordpress.org/plugins/wordpress-mu-domain-mapping/ - it would be appreciated. So far we haven’t been able to get either of these working properly.

We saw this post: Domain mapping multisite - but this appears to need a re-provision of the server each time a site is added. We would like to avoid this.

Our current process

First we create a database dump backup

wp db export --allow-root

Use WP-Cli to search-replace example.mydomain.com with mynewdomain.com in the /srv/www/mydomain.com/current directory

wp search-replace example.mydomain.com mynewdomain.com --allow-root --network

Create an Nginx Conf file by

cd /etc/nginx/sites-available
cp mydomain.org.conf mynewdomain.com.conf

replace:

server {
   listen 443 ssl http2;

  server_name   mydomain.com;
  access_log   /srv/www/mydomain.com/logs/access.log;
  error_log    /srv/www/mydomain.com/logs/error.log;

  root  /srv/www/mydomain.com/current/web;
  index index.php index.htm index.html;

  charset utf-8;

...

with:

server {
   listen 443 ssl http2;

  server_name   mynewdomain.com;
  access_log   /srv/www/mydomain.com/logs/access.log;
  error_log    /srv/www/mydomain.com/logs/error.log;

  root  /srv/www/mydomain.com/current/web;
  index index.php index.htm index.html;

  charset utf-8;

...

and replace:

server {
  listen 80;
  server_name mydomain.org www.mydomain.org;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl http2;
  server_name www.mydomain.org;
  return 301 $scheme://mydomain.org$request_uri;
}

With:

server {
  listen 80;
  server_name mynewdomain.org www.mynewdomain.org;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl http2;
  server_name www.mynewdomain.org;
  return 301 $scheme://mynewdomain.org$request_uri;
}

Then restart nginx:

nginx -s reload
service php-fpm7 restart

Now create a symlink the in the sites-enabled directory:

cd /etc/nginx/sites-enabled
ln -s ../sites-available/mynewdomain.conf .

Ok, my bad. Fixed this a few minutes later using this user’s suggestion: Wordpress Multisite Domain Mapping

We’re with him on not understanding why this fixed the issue. Does anyone see any protentional problems with this fix?

1 Like

This is quite interesting. I’ll probably be having the same problem soon but it’s strange that there is no easier way of doing this. I will probably be using Mercator from HumanMade for domain mapping but would be nice to have this automagically setup.

Having the same situation.
Would be nice if the hack in application.php would no be needed.