Moving from a dev to live WordPress site?

Tags: , ,

Wp-DevToLiveIf you’re like most website developers, you probably do most of your development on a subdomain (ie dev.domain.com) as opposed to the live site.

Welll, this is all fine and dandy until you need to move your nice, new WordPress site from dev.domain.com to www.domain.com — all of your images, links, site name, site domain, etc all have links tied to the dev URI.

Before, I was using ‘the old way’ (see below), but I’ve since found out that, while my script below works for very ‘vanilla’ installs of WordPress, if you have any plugins that store or serialized data, and the string length changes, it very well could break some stuff, so use that with caution.

Instead, what I’ve found is this: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

Here are the (NEW) steps I take when I copy a development site and make it live:
  1. Create a copy of the database (using PHPMyAdmin)
  2. Create a new database (using PHPMyAdmin or cPanel, depending on your web host)
  3. Create a new user for your live site (again, PHPMyAdmin or cPanel)
  4. Restore your copy of the database from the dev database to the live database (using PHPMyAdmin)
  5. Edit the wp-config.php file to point to the new database / username / password (usually starts ~line 17):
  6. Copy the folder (downloaded from this site: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/) to your WordPress root directory so it looks similar to this:
  7. Browse to www.yourdomain.com/your-secret-search-replace-folder (or whatever you named the folder on your on your new host location)
  8. You’ll notice that it pulled database details automagically from the wp-content.php file we edited in step 5 :)
  9. At the top, you’ll see fields for “Replace” (OLD domain name – dev.domain.com – goes here), and “With” (NEW domain – www.domain.com – goes here)
  10. There’s a “Dry Run” option – this will let you see what will be changed before you commit to the change – I typically run this just to make sure I didn’t do something silly before.
  11. Click “Run” and wait for it to finish.
  12. Check to make sure that www.yourdomain.com is now using your newly transferred WordPress site
  13. MAKE SURE YOU DELETE THE SEARCH AND REPLACE TOOL — if you leave this up and someone finds it, they will see your database connection details (including username AND password) — this is a great way for your new site to get hacked…
  14. No, really – go back and DELETE THE SEARCH AND REPLACE TOOL!

Enjoy!


 

The old way (use at your own risk):

Now what?

I looked all over for a simple MySQL Script that I could run to update all occurrences of my dev URI to my live site to no avail. So I took it upon myself to figure it out myself… and I’m a nice guy, so I thought I’d share.

Here are the steps I take when I copy a development site and make it live:
  1. Create a copy of the database (using PHPMyAdmin)
  2. Create a new database (using PHPMyAdmin or cPanel, depending on your web host)
  3. Create a new user for your live site (again, PHPMyAdmin or cPanel)
  4. Restore your copy of the database from the dev database to the live database (using PHPMyAdmin)
  5. Run the 4 queries (below) on the database to update all domain occurrences to the live domain
  6. Copy all of the files from the development installation of WordPress to the live folder (I always copy all of the old files off first – just in case something doesn’t work 100% I can roll back to the old site while I troubleshoot)
  7. Modify the “wp-config.php” file in the root with the new database credentials and save.
  8. Reload the live site.
  9. Assuming I did everything right, bask in the glory of my newly launched site.
Here are 4 queries that you need to run in PHPMyAdmin:
It really is just that easy… yeah, I know. Easy is relative. But if you’re developing a website, you should know how to do (or at least how to find) all of the steps above.

Hope this saves someone some time!

 

Disclaimer:
  • I can’t guarantee this will work on all versions of WordPress, but I have used it successfully with 3.5.0, 3.5.1, 3.6.0, 3.6.1, 3.7.0, 3.7.1, 3.8, and 3.8.1
  • This will only update the values in the default WordPress tables. If you have plugins installed that also reference the domain, you’ll need to verify and update those fields manually (or find the tables / columns that reference the site address [URL]).
Top