Animals Migration 1 1295692209

How to migrate your WordPress DataBase to a new URL

0

I get it. Sometimes you just need a change of scenery. A new digital landscape for your precious website. And in the process, you just wanna make sure nothing gets lost…

I just transferred all the files from my old wordpress site to my new server. When I try to login at /wp-admin, I'm directed to the old server login. Why? – frustrated wordpress friend
Ugh. I've transferred all my WordPress files, even updated the wp-config.php file, and I'm still having problems migrating my WordPress blog to a new domain. Help! – 'nother friend

It sounds a little ridiculous to even have to depend on a third-party script to cleanup the mess of migrating a WordPress instance from one domain to another. It’s honestly baffling to me that WordPress still stores URL’s in the database. That being the case, the solution to the problem is simply running a search-and-replace on the relevant tables in your WordPress database. Here’s a tool that let’s you do just that.

Click Here to Download the WordPress Search and Replace Script

This simple script changed over a thousand instances on my migration. It took under 2 seconds. Saving me what has taken hours in my first few attempts at migrating a WordPress site. Hope it helps you!

Using the Script
  1. Download the zip.
  2. Unzip.
  3. Upload to your /wordpress directory.
    The same directory as your wp-config.php file. It’s gonna read that to connect to your database.
  4. RENAME the file.
    This is to protect you from any nasty bot finding it and using it for evil.  I like to rename it to a random string of characters like R_Gf583RHWIU.php, then just copy and paste it into the browser, so  even if some(one) finds it in the small amount of time it’ll exist on my server, it’ll look mostly meaningless.
  5. Navigate to the file.
    This will be /your-wordpress-root/YOUR-RENAMED-FILE.php
  6. Follow the onscreen instructions.
Migrating the Database

After connecting to your database through the onscreen instructions mentioned in step 6 above…

  1. Enter YOUR-OLD.DOMAIN into the first field
  2. Enter YOUR-NEW.DOMAIN into the second field.
  3. Hit Continue.

If everything was entered properly, your new site should be ready!

What if my WordPress install is in a subdirectory on one of the servers, and not the other?
To/From sub folders

If either wordpress install is in a subdirectory of your domain (If your wp-config.php file is in a place like, mydomain.com/my-wordpress-install/wp-config.php), then you’ll need to specify that in the fields above. In my case it was :

  • OLD: dev-server.jollyscience.com/wordpress
  • NEW: www.jollyscience.com
I prefer not to use the trailing slash in the above fields,  to make sure it covers both www.jollyscience.com and www.jollyscience.com/some/path
I did everything you said, and now I can login and change content, but my page and post URLS are returning 404 errors!" – reader

Did you remember to update the .htaccess file? (at first, I didn’t) If you have the permissions set properly, you should be able to solve this by revisiting your ‘Permalinks’ page in the WordPress admin.

Updating .htaccess

To edit your .htaccess file through the WordPress admin panel, visit: Settings > Permalinks

If you edit these settings and the pages are still not working, look to the bottom of the Permalinks page. If you get the message below, you’ll have to update the .htaccess file manually…

Updating .htaccess (manually)

This is likely to be different for you, but in my case, as you see in the info box above, I was moving from a subdirectory (/wordpress) to the root directory. In order to solve the 404 errors, I simply needed to update the .htaccess file from:

RewriteEngine On
RewriteBase /wordpress
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]

… to the new settings of…

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

We’re done! Now don’t forget to delete the search and replace script. If you followed along, it will be located at: /your-wordpress-root/YOUR-RENAMED-FILE.php

Happy Blogging!

    No Twitter Messages