Link to home
Start Free TrialLog in
Avatar of egoselfaxis
egoselfaxis

asked on

WordPress - changing the main site URL globally .. both in settings and in pages / posts

I've been developing a WordPress site under a staging URL for the past few months, and am nearing the point where it's time to deploy it.  We won't be needing to migrate the site to a different server, and will instead just be leaving it exactly where it is and changing the main site URL with the top level domain.  

I already know how to change the main site URL in the WordPress admin, as well as in the wp_options table using PHPMyAdmin.  I've also experimented with various different "search and replace" WordPress plugins to handle the updating the the site URLs in pages and posts .. but I never thought them to be 100% effective, as they always seem to miss things .. like URLs in the theme's settings, for example.  

What's the best and safest way to update the main Wordpress site URL globally in the database .. meaning everywhere that it occurs?  

Thanks.
- Yvan
Avatar of David Favor
David Favor
Flag of United States of America image

This is a near daily occurrence with my private hosting clients.

Here's how I do this, for non-SSL sites. If you're final site will be SSL, let me know + I'll post the extra SSL steps.

So let's say your moving from dev.foo.com to foo.com as your final URL.

This is a bit tricky as some occurrences of your URL will be serialized data + if you change this incorrectly, your site will act flakey or crash.

phpMyAdmin contains no serialized data intelligence, so if you use phpMyAdmin, likely your site will glitch or crash.

There are two easy ways to do this.

1) On the command line

Use --dry-run to count number of changes to be made. If there are 1000s this may take a long time.
cd to your WordPress install directory + do this.
wp search-replace 'http://dev.foo.com' 'http://foo.com' --precise --recurse-objects --all-tables --dry-run 2>/dev/null

Open in new window

Remove --dry-run to make changes.
cd wp-root-dir
wp search-replace 'http://dev.foo.com' 'http://foo.com' --precise --recurse-objects --all-tables 2>/dev/null

Open in new window


2) Command line give you shakes + sweats? Try the Duplicator plugin + when you do you restore, Duplicator will auto-magically fixup any serialized data.

Also be sure to name your database something reasonable, like $project_$domain_v$version where.

$project is a short tag to organize databases.

$domain is "foo".

$version is the next sequential version of your database, so you don't accidentally overwrite your dev database, till you have a successful migration.
Avatar of egoselfaxis
egoselfaxis

ASKER

Thanks for your reply David.  I'm leaning towards experimenting with the Duplicator plugin you've referenced.  I just have one question about that ...

As I mentioned, .. I won't be needing to migrate the site to a different host or to a different physical location on the server.  I'll only be needing to change the main site URL in the database ... everywhere that it occurs.  Will this duplicator plugin allow me to do that .. without having to copy over or overwrite all the files?    

Thanks,
- Yvan
After migrating... geez... likely 1000s of sites at this point, here's how I approach this.

I setup a file hierarchy like this, where john-smith is a client or project name...

/sites/john-smith/dev.foo.com/wordpress - where dev occurs
/sites/john-smith/foo.com/wordpress - where production site will live.

Open in new window


Then if using Duplicator, just run a normal backup of dev.foo.com + create your new database for foo.com + upload the Duplicator installer + archive file into /sites/john-smith/foo.com/wordpress + run a Duplicator restore.

If you try too effect changes in dev.foo.com + somehow destroy the database, then you'll have to destroy dev.foo.com + restore from backup + reload database. This all becomes very complex.

If you leave dev.foo.com alone, then if something goes wrong you still have a working site + you can start the process over again.

After foo.com is working, then destroy dev.foo.com - database + files.
It's kind of too late for me to use this approach, as the DEV site that I'm working on is currently being served up from my /public_html folder, and I'd prefer to not have to move things around at this point, .. or set up a copy of the site, etc.  I plan to back everything up to my local machine ahead of time, of course.  But I'm really just trying to find the quickest and safest way to apply the necessary database updates.  

So would this Duplicator plugin allow me to do that (only implement the database updates)?  Or do you recommend a different approach?  I'm on a shared hosting hosting environment by the way (Linux based).  

Thanks,
- Yvan
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for this!  We've specified a tentative launch date of Monday August 31st, .. so wish me luck!

- Yvan
Good luck!