• Home
  • Comics
  • Archive
  • Videos
  • Contact
  • Tumblr

Mangos and Peaches

Create Inspiration, Inspire Creativity

Feed on
Posts
Comments

Moving a wordpress blog…

Jun 30th, 2008 by Chris

Is serious business. It’s also time consuming if you’re as anal as I am with the details and want to move everything while keeping the links between the web files intact. So here is a short article on my experience doing this with my notes for anyone that cares.

This will get a bit technical and I know that there are people that either a) don’t care or b) won’t understand it. So if you fall into one of the two categories I’ll save you some time and tell you not to read beyond this paragraph. For those that are still interested, continue reading if you wish. This is more of a reference for myself just in case I need to do something like this again.

Introduction:
I have moved websites before. My first site was self-contained inside a folder on my fathers webserver. It was built using only HTML using Dreamweaver. As I started to create more and more content naturally the site grew and I decided it was time to get my own space. Moving those files were as easy as copying them from one server to another. The site was also small enough for me to go in and manually change the links to reference the new domain and server IP address. Then I started blogging.

Started off with a simple blog on blogger that was hosted on their free servers. I moved to wordpress after a month for several reasons. First I wanted to host my own blog (I was never a fan of their ads and top navbar which you HAD to have if you were hosting with them for free). Second, I wanted more control over the theme of the blog (eventually I wanted to make my site revolve around the blog). And the most important was the organization of the site. I liked the idea that the site archives itself and keeps itself somewhat organized.

To make a long story not as long: I had to change my domain name and change the site files and every link to point to the new domain name.

How to do it?
It’s actually not that much of a headache as long as you pay attention to the details and get it right the first time. Oh, and don’t forget to make back-ups. I’ve had to learn this the hard way more than once, but I’m getting better and keeping up-to-date back-ups of all my files.

Old domain name: mangoandpeaches.com
New domain name: mangosandpeaches.com

So I have to rewrite over 100 files that have links as “www.mangoandpeaches.com/whatever” and now I need it to say: “www.mangosandpeaches.com/whatever”. One letter is preventing everything on the site from working under the new domain. This should come as no surprise, anyone that has dabled with PHP code knows that even a space at the beginning or at the end of your code will make everything all screwy. The simple solution that comes to mind is to use BBEdit to execute a find and replace command. Find: “mangoandpeaches.com” Rename: “mangosandpeaches.com”. Worked like a charm. I had to go back and manually update a few strays that it didn’t replace for some reason, but for the most part it saved me countless hours or reading through code and adding an “s”.

So the internal links in the sites files are fixed, but I encountered another problem.

The WordPress Database:
Wordpress uses absolute paths in the URL links rather than relative paths. So now I have to change the database files to reflect the new domain name as well. This was the part that worried me because I’ve never really dealt with MySQL.

Luckily I had a book that I bought a few years ago that I used as a reference starting point. After some heavy reading I found two SQL Statements that saved the day for me (Literally). Now if you’re actually attempting to do this you’ll need to log into your database as the root user. You can do this through a terminal window or by using the web based SQL windows your host provides. Or at least they should provide this service, if not logging in through a terminal window was my first option so I can keep logs of the changes.

First we need to change the wordpress options to reflect the new domain name. This can be done be executing the following Statement:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

Naturally you’d replace “old-domain” & “new-domain” with the respective information. After this you will need to fix URLs of the WordPress posts and pages, which are translated from the post slugs (you do use post slugs don’t you? ;P), and stored in database wp_posts table as guid field. The URL values in this field are stored as absolute URLs instead of relative URLs as I mentioned before, but they can be updated with the following SQL query:

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');

Finally you’ll have to change the links within the actual blog posts themselves to reflect the new domain. I should have to explain this part, but if you have any pictures hosted on your webserver you’ll have to run this Query to make sure your images and trackback links remain in working order. To make these changes run the following Query:

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

This was the tricky part. Took me a while to find out how to do this without going in and physically changing the URLs myself. I’d have to give a special thanks to mydigitallife.com for saving me here. I found a very helpful topic that cleared any doubt I had about changing around my database values.

After doing all of this I changed m hosting account to point to the new domain name and began to check over the site to make sure everything was in working order. And it was! The only issue I had was with the Aloof side of the site with all of the comics, but it wasn’t loading right because I had left the Aloof database unchanged. So I simply ran the same set of statements while logged into the other database and voila, everything was in working order again!

Final notes:
This information is useful way to update your blog and site when switching domain names. All of the files I had were left on the same server I’ve had for years, I just pointed it to the new location. If you had to switch servers the process would be more involved because you’d have to physically copy the files to the new server and export your database which makes things significantly more complicated. I’m not saying it can’t be done, I’m positive it can if you’re willing to put in the time and effort.

Hopefully this information has becomes useful to someone out there. I know there are a few of my college professors that would be proud of me after reading this. I actually created a weblog!

Posted in Tutorial, Web Tech | No Comments

Comments are closed.

  • Latest Tweets

  • Recent Photos

    Gainesville Sunset

    Jacksonville Skyline

    Florence Blue Hour

    DSC_3489

    DSC_5451

    More Photos
  • Tag Cloud

    Aloof Amsterdam Animation Art Artist Batman Chris Acuna Color Comics Cool Crazy Creative Design Digital Drawing Family Friends Funny Games Good Times Illustration Moleskine Movies Music Painting Photo Photography Photos Photoshop Poster Sign Making Signs Sketch Sketches Spain The Dark Knight Trailer Travel Tutorial Vacation Video Video Games vinyl Vinyl Graphics WoW
  • Category Archive

  • Archives

  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org

Mangos and Peaches © 2012 All Rights Reserved.

MistyLook made free by Web Hosting Bluebook