Sometimes this happens, you’ve built the site and have to or want to change the domain it’s on. Or you did dev work on a different domain and now it’s time to go live.
The domain name is actually stored in numerous places in the database, as well as one line in wp-config.php. Every single one of these will need to be changed.
Before you do anything, backup. Go to phpMyAdmin, select your database, and choose Export. Save it to your computer. We’ll be making a copy of this and working on the copy. This way, if anything goes wrong, we still have our backup.
The database information – table structure, content, everything really – is stored in a file with the extension .sql. This can be read and edited in a simple text editor. If you’re a Windows user, try NotePad++ instead of the default Notepad.
Simple do a find and replace on olddomain.com to newdomain.com. Save your copy.
Method #1:
- on the live site, verify you have that backup, then drop all the tables in the database.
- import your edited sql file with the new domain name in it. (phpMyAdmin -> Import tab.)
- edit wp-config.php with the new domain name
- change the DNS records for the domain so the new one points to the right spot on your server if you haven’t done it already.
Method #2:
- create an entirely new database. Use an existing db user & password, or create a new one – your choice, as long as they have ALL privileges on this database.
- import your edited sql file with the new domain name in it. (phpMyAdmin -> Import tab.)
- edit wp-config.php with the new domain name AND the new database name, plus the new db user & pass if you did this.
- make sure your new domain is pointing to the right spot.
Do whatever you like with the old domain.
[...] This post was mentioned on Twitter by andrea_r and John Turner. John Turner said: RT @andrea_r: ever need to change the domain name on your wpmu install? http://bit.ly/2EHmst [...]
I put a copy of my live server onto a local machine and found all instances of the domain in the db and changed them. reading this made me go doh! search and replace on a single file would have been sooo much easier! :-z
Yeah, it was definitely a DOH! moment.
If you download the SQL backup file, you can use InfoRapid Search & Replace to quickly replace all instances. Will search through all the files within a folder, open them, do the replacement and then save and close. Can run through 1000 replacements in a minute or less!
It has saved me a ton of time in my Find and Replace needs! http://www.inforapid.de/html/searchreplace.htm
Hi,
Thanks a bunch for the quick tutorial!
I have a question: When you say “change the DNS records for the domain so the new one [...]“, where do I do this? In the .htaccess.., in the wp-config?
Thanks again.
This does not address the issue of poorly designed plugins that choose to save paths and urls in arrays in their own options. These arrays are generally serialized. Merely doing a search/replace will likely break the array unless the number of characters in the new name is exactly the same as the old name.
Otherwise, the serialized array wil have to be hand checked and have the character count adjusted accordingly.
Does these methods also apply to forcing www preference, that is changing domain name from domain.com to http://www.domain.com?
No, they do not. The www gets stripped elsewhere in the code.
Hi Andrea
Does your ebook cover how to setup WPMU so that you can set up multiple sites with the www. prefix on the domains?
If not do you know if it is possible?
Thanks
Richard
This process for me was quite smooth…moving from a dev server/domain to a new host/new domain. Sadly the new host does not support wildcard subdomains, so I’m forced to change the naming scheme to: domain.tld/blogname
Any suggestions on how to achieve this?
(also posed this question to the forum at mu.Wordpress.)
Best – H
Hi Andrea — awesome as usual!!
Quick question: I don’t see which line to change in the wp-config.php? Any help??
Am I uncommenting the redirect section and entering from the old domain to the new??
Thanks!
Oh.. I’m using 2.6… I don’t see where to enter or change “DOMAIN_CURRENT_SITE”.
Is it just an add?
Thanks, again!
Oops, nevermind. I saw that the new wp-config.php lines are added as part of the 2.7 upgrade. I did the upgrade as mentioned in another of Andrea’s posts and, voila… 2.71 living on a new domain.
Great post — thanks Andrea!
-Chris
There were one or 2 more added in 2.8 as well.