Change the Primary Domain for a WordPress Multi-Site Network
If you run a multi-site installation of WordPress, the thought of implementing a dramatic change that could impact every WordPress website on your network is enough to cause you grief. However, don’t dismay. The process for successfully changing the primary domain name is fairly simple.
Step 1: Point the new primary domain name
All domains on your WP multi-site network run through the primary domain name. In order to ensure that there is minimal down-time for your network, the new primary domain name should successfully point to the network prior to committing the switch. In order to do this, you will need to complete the following:
- Edit the DNS for the new primary domain name with the nameservers where your network is hosted via your registrar.
- Add the new primary domain to your hosting package through your hosting control panel, and point it to the installation path of your network.
If you have configured your network to work with subdomains, you will need to create a wildcard subdomain for the new primary domain.
Step 2: Backup your database
It goes without saying that backing up your database before surgically editing it is a good idea. You’ll need to export an SQL file. It is also a good idea to make an additional copy of the SQL file – one copy for editing, and the other for just in case you need to restore the network to it’s prior state.
Step 3: Edit your wp-config.php file
Around line 85 in the wp-config.php file is a reference to your old primary domain name. You’ll need to edit the domain to reflect the new primary domain.
define( 'DOMAIN_CURRENT_SITE', 'YourOldPrimaryDomain.com' );
Step 4: Edit your database
With your editable copy of your database, you’ll need to open the SQL file in a text editor (not an IDE). Using the Find & Replace function/tool in your text editor, you’ll need to find all instances of your old primary domain name (excluding “http://www.”), and replace all instances with the new primary domain name. Once complete, save the changes.
Step 5: Make the switch
Once you have confirmed that the DNS for the new primary domain name has fully propagated, it is time to commit the changes you’ve made to complete the switch.
- Upload the updated wp-config.php file via FTP if you haven’t done so already.
- Dump/drop all tables in your database.
- Restore your database by importing the edited SQL file
Final thoughts
You’ll likely need to make additional configurations to the settings for the new primary domain name in WordPress if the old and new primary domain names differ dramatically in concept (i.e. site name, titles, etc.).
Also, if you originally had an email address using the old primary domain that had been attached to a particular site within your network, assuming you want email routed through the new primary domain, you’ll need to create the mailboxes for all the usernames that were previously attached to the old domain. However, if you want to continue routing email through the old domain, you’ll have to update the address in the settings of each site.
Other than that, you’re done!
NOTE: Do not attempt if you are wary of or unfamiliar with modifying your database. Always, always, always backup your data. Use this technique at your own risk.
.
Tags: database backup, DNS, domain name, multi-site network, primary domain name, subdomain, wordpress, wp-config
Hi
I followed these steps to change my site’s primary domain. After I’ve done all the steps, entering my new url in the browser gives an “Error connecting to database” issue.
Any ideas what I could be doing wrong?
Thanks for any help!
Dear Dev,
There’s nothing in the instructions that should impact the database connection except for the DNS propagation step. It may take time for the DNS to fully update, and until it does, you may experience this issue. Try flushing your DNS cache. In Windows, type ipconfig /flushdns into the command prompt, and then press F5 to refresh your website.
If the problem persists, then perhaps there were some additional modifications to the host? Did you also change the primary domain of your host account? Some hosts use your domain as part or whole of the MySQL database host address. Make sure your connection settings reflect any changes made to your host account.
Under Step #5, what does “2. Dump/drop all tables in your database.” mean?
I just want to say thank you as these instructions were spot on and helped a lot. There are a lot of options out there for WordPress and it can be overwhelming sometimes so once again thanks for the step by step.
Sean
Admin is correct I have waited up to 48 hrs for update
It’s dangerous to do a search + replace on a SQL dump of a WordPress site because WordPress stores a lot of serialized data and replacing text within a serialized string will corrupt it. To ensure you don’t break anything, you have to be a little more surgical than what’s proposed. Like others have said before me, it’s a regal pain!
Matt,
You’re partially correct. Since we’re only doing a search and replace on just the domain name, we wouldn’t encounter an issue with serialized values. Even a serialized domain is wrapped like so: s:15:”www.website.com”;. Therefore, a search and replace wouldn’t be an issue because it can read and replace a wrapped serialized value without breaking anything. If a plugin developer unfamiliar with the WP API decided to base64 encode a script path that included the domain, for whatever reason, then that would present an obvious issue. However, I’ve not encountered an issue while using this method the many times I’ve done it.
Thank you! Very very helpfull!
[…] Change the Primary Domain for a WordPress Multi-Site NetworkUse this simple step-by-step instructional guide to learn how to change the primary domain name of your WordPress […]
[…] out how to change the domain of the primary blog in a WordPress Network. A Google search led me to these instructions, which actually are a bit more heavy-handed than they need to be but contain all the right […]
The serialised stuff will give you a lot of grief if your new domain name is a different length than the old one.
When you look at the serialised data, it looks like this:
s:15:”www.website.com”;
the 15 after the ‘s:’ is the length of the serialised data, so if your old and new domain names are different lengths, you’ll need to change this tot he appropriate value.
Do yourself a favour and make sure your new domain name is the same number of characters as the old one (I register .com for my main domains, and keep a .org for dev/test/demo to make life easy)
cheers
Michael.
Hi, with regard to the serialized data issue, a download is available that reportedly allows you to correct this when changing values in Multisite. It’s even recommended on WordPress’ documentation itself:
interconnectit.com/124/search-and-replace-for-wordpress-databases/
Worth looking into — albeit with a great deal of caution and plenty of backups first!
I was sweating bullets knowing I was the one who got assigned to do this at my company. I triple-checked each step, it was an excruciating process, (for me anyway). When it came time to load the URL of our new domain in the browser and login in to the first blog… bada bing! it worked first time. all I have to do is change the email addys. Even a blind squirrel can find a nut sometimes I guess…
I tried and it worked! Thank you so much for the guide!