WordPress Multisite with Wildcard DNS and/or SSL on Dreamhost

Although Dreamhost supports Wildcard DNS, they don’t support Wildcard SSL (except on DreamCompute), so WordPress Multisite with wildcard subdomains may not be the best choice.

TL;DR

  1. Dreamhost & Wildcard DNS
  2. Setting up WordPress Multisite
  3. I suggest not using Wildcard DNS with Multisite subdomains – and show how to get SSL on Multisite by registering each subdomain first

Years ago, I had Dreamhost set up Wildcard DNS for me, but it frustrated me that I could never get secure HTTPS connections for the subdomains.

Turns out many people have also had issues with this. And although I still don’t have a Wildcard SSL certificate solution that works, I have found a work-around that will suit my present situation. 

Note

This work-around basically nullifies my Wildcard DNS because I have to register each subdomain individually from the Dreamhost Panel.

In any case, this is the setup I currently have and Dreamhost’s position on each:

  1. Wildcard DNS on Dreamhost
  2. WordPress Multisite (read this Before creating a Network)
  3. SSL on those Multisite subdomains
    • Not supported by Dreamhost unless using DreamCompute (requires additional configuration)

#1 Setup Wildcard DNS

Two simple steps:

  1. Upgrade your hosting plan to VPS or a Dedicated server
  2. Contact Dreamhost Support to set up Wildcard DNS for you

#2 Setup WordPress Multisite

First, ask yourself if you REALLY need a Multisite installation, and if so, how many subdomains you expect to need. In fact, it’s actually an easier option to opt for subfolders rather than subdomains for your extra sites as this would make your SSL and Wildcard DNS problems virtually disappear.

With subfolders

  • SSL would load from the root domain
  • You wouldn’t need to create additional subdomains at all

Second, ask yourself if you REALLY need Wildcard DNS. As noted above and below, Dreamhost doesn’t support Wildcard SSL certificates.

If you really need Wildcard DNS and Wildcard SSL 

  1. Consider moving to DreamCompute – which does support this (with additional configuration on your part)
  2. Plan to get your hands dirty doing this all on your own
  3. Consider moving to a hosting provider that supports this configuration
  4. Reconsider Wildcard SSL altogether and just accept that you’ll be registering subdomains through the Panel and getting Let’s Encrypt certificates for each one (as outlined below)

Articles to Read for Setting up Multisite

#3 Get SSL on your subdomains

Non-Wildcard SSL

The simplest way to get SSL on a subdomain is not to use wildcard subdomains in the first place. 

One of the most compelling reasons to use Multisite with Wildcard DNS is if you want to allow the creation of multiple subdomains without registering them through your Panel first. This would enable you to, for example, allow users on your website to create their own subdomain blogs within your larger site when they register or subscribe to your site’s membership plan. (This is the reason I’d originally wanted Wildcard DNS.)

But, the problem with hosting such a site on Dreamhost is that they don’t support Wildcard SSL certificates, so every site created through WordPress Multisite will say it’s “insecure” even if you load it over HTTPS (and Google Chrome will also put up a blocker alerting you of the fact).

Main idea

Don’t employ Multisite to (initially) create subdomains.

I tried the following methods to get SSL on my subdomains and each failed:

  1. Create a new subdomain (v2012.site.com) via Multisite
    • The subdomain does not use the main site’s SSL
  2. Register that same Multisite-created subdomain through the Dreamhost panel and “mirror” the site to the root site. Then get an SSL certificate for the “mirrored” domain (v2012.site.com)
    • “Mirroring” basically says “set up the exact same site at both locations and use the same SSL” – so again, only the main site’s SSL will work
  3. Change the “mirrored” site to “redirect”
    • This bypasses the subdomain altogether and maps all traffic from the subdomain directly to the main site (site.com)

Finally, after much trial-and-error, I stumbled upon Ian Dunn’s article that provides the solution.

Solution

Setup your subdomains as “Fully hosted”, but set the web root (Web Directory) to the same directory as the root domain. (And re-save SSL settings if applicable.)

Be sure to also now get yourself a FREE Let’s Encrypt SSL certificate before you save these Settings (click HTTPS under the Web Options section).

(Re)create the Site through WP Multisite

The problem with doing things this way is that now you’re no longer really taking advantage of your Wildcard DNS. And actually, just creating a subdomain through the Dreamhost Panel won’t set up WordPress Multisite to run on the subdomain.

So, the next step is to go back into your Multisite installation at the root of your domain and create (or delete and recreate) your subdomain Site.

Re-saving SSL settings

Now, if the (new) site still isn’t loading HTTPS securely, there are two possibilities for this:

  1. You didn’t wait long enough for the Let’s Encrypt certificate to take effect (in that case, refresh the page in 5-10 minutes and check again)
  2. You may need to re-save your SSL settings (as Ian Dunn outlines)

To re-save your SSL settings, click the https On link in the center of your Domain Registration listing table under the Manage Domains menu item.

On the next screen, check the box marked Copy non-secure settings and Save it.

Force HTTPS

There’s one more thing to be sure of – that HTTPS is always loaded regardless or whether or not an HTTP or HTTPS URL is accessed. You can do this with the following code inserted into the top of your .htaccess file in the root of your Multisite installation directory:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

WP Migrate DB Manually : Multisites & Single Sites

Recently, I needed to migrate a WordPress site from a Multisite installation to a Single Site .com.

I usually use the WP Migrate DB plugin because it works well for my basic needs, but going through the Multisite -> Single Site transition very manually, sure made me see the value in the Pro version of their plugin.

For a full video tutorial walkthrough of the transfer process, I highly recommend Morten Rand-Hendricksen’s Lynda.com course on the subject. Below are a few step-by-step notes detailing the process.

Setting things up

  1. Setup your <TARGET> site first
    1. Install WordPress with default options
  2. Migrate plugins, themes, and uploads
    1. Move them from the <ORIGIN> site -> the <TARGET> site *
    2. Using FTP, I download what I want to keep to my Desktop
    3. Then, upload them back to the NEW site (watch a video, it’ll take a while)
  3. Install WP Migrate DB on both sites and open it

migrate_db

Single Site -> Single Site

  1. From the <TARGET> site:
    1. Copy the URL -> <ORIGIN> site’s “New URL”
    2. Copy the file path -> <ORIGIN> site’s “New file path”
  2. On the <ORIGIN> site:
    1. Export the SQL file
  3. Prepare <TARGET> site’s wp-config.php file **
    1. Open <ORIGIN> site’s wp-config.php file
    2. Find $table_prefix down in the file and copy that table prefix String
    3. Replace $table_prefix String in the <TARGET> site’s wp-config.php with the <ORIGIN> site’s String
    4. Save the modified <TARGET> site’s wp-config.php
  4. Open phpadmin on the <TARGET> site
    1. Drop all <TARGET> site’s default wp_ tables
    2. Import <ORIGIN> site’s SQL file (from WP Migrate DB)

Multisite -> Single Site

I did all the previous steps for the Multisite configuration (to test it), but ended up with the default site and not any of the Posts or content I needed in my subsite. Luckily, DeliciousBrains has written up a tutorial detailing this kind of migration as well:

Extracting a Subsite from Multisite to Create a New Single Site Install

These are the steps I followed (and some notes about mistakes I made):


Notes:

* Originally, when you want to move your uploads folder from Multisite to a single site, you’ll notice another folder in the uploads folder:

  • /uploads/sites/4/2016/
    • The sites folder contains all the uploads for each subsite
    • The 4 (or other numbered folder) is the site ID (you can find the site ID by going to that particular site’s admin Page)
      • http://sitename.com/wp-admin/network -> Sites -> Subsite name
      • http://sitename.com/wp-admin/network/site-info.php?id=4
  • So, you move the content from the site ID’s folder to your <TARGET> site’s uploads folder
    • /uploads/sites/4/2016/ -> /uploads/2016/

** This also means that your $table_prefix String in wp-config.php will include this site ID between the wp_ and the rest of the String:

  • Ex: $table_prefix = 'wp_ex54gTv'; will be 'wp_4_ex54gTv' in the SQL database for your particular subsite

1. Prepare the SQL Export

  1. Migrate plugins, themes, and uploads
    1. Move them from the <ORIGIN> site -> the <TARGET> site *
  2. Replace URL and file path from the <TARGET> site:
    1. Copy the URL -> <ORIGIN> site’s “New URL”
    2. Copy the file path -> <ORIGIN> site’s “New file path”
    3. Click “Add Row” to add subsite details
    4. //subsite.sitename.com -> //newsite.com
    5. Click “Add Row” to replace your uploads folder Strings
    6. /uploads/sites/4/ -> /uploads/

migrate_db_subsite

Now, you’re ready to Export the file.

DeliciousBrains says:

  1. Expand the “tables” section and select the “Migrate only selected tables below” option.
  2. Select all the relevant subsite tables as well as the “users” and “usermeta” tables.

However, that wasn’t an option for me while using the free version of the plugin. Therefore, ALL the next steps were very manual. But, I think the image from their website is helpful to know which tables to keep and which to get rid of in your SQL file:

Source: DeliciousBrains.com
Source: DeliciousBrains.com

Basically, you will want to KEEP all the WordPress data for your subsite (everything with the site ID between underscores _4_ and DELETE all the WordPress data for the main site.


Notes:

* This was one of my problems going through. I didn’t DELETE all the main site data from the SQL file, so it would import the subsite data, then overwrite it with the main site data.


2. Prepare the SQL upload

  1. After preparing everything as described previously, Export the SQL file
    1. I turned OFF Gzip so I could immediately modify the file after download
  2. Modify the .sql file in any code or text editor
    1. Go ahead and go through and DELETE all the SQL tables that we didn’t need to select (everything that ISN’T blue in the image above).
    2. These will be listed in the alphabetical order shown in the image, so should be easy to find. DELETE everything from wp_blog_versions to wp_terms (because you’ll notice you still have wp_4_terms and the like that contains your subsite data
    3. Find and Replace any instances of wp_4_ with just wp_
    4. Save and close the file
  3. Open phpadmin on the <TARGET> site
    1. Drop all <TARGET> site’s default wp_ tables
    2. Import the NEW SQL file (you just modified)
  4. Run cleanup
    1. DeliciousBrains has some SQL queries you can run to remove duplicate usermeta rows as well – these didn’t work for me as the syntax in my phpadmin was wrong, so I manually deleted old users, etc.
    2. Alternatively, it looks like this SQL script will do the job as well

Problems?

  1. Whitescreen of Death? Your theme may be missing from the target site – /wp-admin will still work – choose a different theme, or be sure to upload the one you want
  2. Manual DB import fails? Don’t use GZIP and export it again (larger file size)
  3. WP Migrate DB ate my posts? This is a migration, not merge – use WP Migrate DB Pro’s push/pull if you just want “updates”
  4. Media files not working? Be sure everything is uploaded (and for Multisite, be sure you changed the upload folder during your SQL export – from /uploads/sites/4/ to /uploads/
  5. Migration failed? Be sure the $table_prefix Strings in your <TARGET> site wp-config.php match those in the <ORIGIN> site’s wp_config.php

Was this helpful?

I hope this write-up was helpful. Let me know in the Comments. I plan to use these notes for my next Migration as well.

Side note: WP Migrate DB Pro can do all of this FOR you automagically. It can also UPDATE your site if there is newer content on one side or the other using their push/pull function. It would be a great option if you do lots of migrations or just want to save yourself the headache of doing it all manually.