Change WordPress to a new url/domain name

I’ve been moving my blog (this blog) to a new provider. I’m now using Amazon AWS, specifically an EC2 Micro Instance, so far I’m very please with Amazons service but since I’m new to AWS I do find that is hard to keep up with all the names, terminology and acronyms of Amazon service.

yesterday I found out that my server IP Address wasn’t static, a friend told me about it when we were discussing things. In Amazon AWS you need to set up an Elastic IP. An Elastic IP is basically an Static IP Address that Amazon provides you with. If you do not set an Elastic IP your server IP will probably be handled out to some other instance if you shutdown the server.

So I set up my Elastic IP and then WordPress kinda die :S.

Here is the problem. Since I’ve been toying with this server for only a few days I haven’t finished setting everything up. This actually meant that when I installed WordPress and Added my first WordPress site I told it this was my URL(domain):


http://50.19.207.248/

Not my real IP anymore.

So after telling Amazon that I wanted a new IP associated with my server WordPress freaked out and it refused to serve the content.
So after some Googling I stumbled upon this post which talks about it

In order for WordPress to understand you have a new URL(IP, domain, etc) you need to modify WordPress DataBase

This was done on a Debian 7u1 x86_64 GNU/Linux

Lets get started
Connect to you MySQL instance


mysql -u root -p

The command above connects to MySQL as Root (It will ask for the root password) you can connect directly to the WordPress DataBase if you know the name or have no access to the MySQL Root account;

First get a list of your databases


mysql>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| myWordPressDB      |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

Then use WordPress db;


mysql>use myWordPressDB;

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

Now lets see our tables


mysql> show tables;
+--------------------------+
| Tables_in_myWordPressDB  |
+--------------------------+
| wp_bpspro_login_security |
| wp_bpspro_seclog_ignore  |
| wp_commentmeta           |
| wp_comments              |
| wp_links                 |
| wp_options               |
| wp_postmeta              |
| wp_posts                 |
| wp_term_relationships    |
| wp_term_taxonomy         |
| wp_terms                 |
| wp_usermeta              |
| wp_users                 |
| wp_wfBadLeechers         |
| wp_wfBlocks              |
| wp_wfBlocksAdv           |
| wp_wfConfig              |
| wp_wfCrawlers            |
| wp_wfFileMods            |
| wp_wfHits                |
| wp_wfHoover              |
| wp_wfIssues              |
| wp_wfLeechers            |
| wp_wfLockedOut           |
| wp_wfLocs                |
| wp_wfLogins              |
| wp_wfNet404s             |
| wp_wfReverseCache        |
| wp_wfScanners            |
| wp_wfStatus              |
| wp_wfThrottleLog         |
| wp_wfVulnScanners        |
+--------------------------+
32 rows in set (0.00 sec)

Now we need to update some tables to match our new site URL, domain, etc.. so WordPress knows about it
NOTE: The Update statements below are based on the names of the tables in the sample above! make sure to double check for you database, tables names, since they may differ from the ones here.

Run this (replace http://old.url with your Old URL and http://new.url with your New URL):
You can also use this page which does that for you 😉


mysql> UPDATE wp_options SET option_value = replace(option_value, 'http://old.url', 'http://new.url') WHERE option_name = 'home' OR option_name = 'siteurl';

mysql> UPDATE wp_posts SET guid = replace(guid, 'http://old.url', 'http://new.url');

mysql> UPDATE wp_posts SET post_content = replace(post_content, 'http://old.url', 'http://new.url');

mysql> UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://old.url', 'http://new.url');

You should see a message saying a few rows changed, if rows changed is equals zero you did something wrong.

Finish up
Now just close the mysql cli


mysql> quit;
Bye

And we should be done try and reload your webpage 😉

Leave a comment