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 .