Relocate WordPress website or folder – straightforward text edits will not do it – tools are required

I found a great article and tool to get started, but it took many attempts to finally move or relocate WordPress website or folder from http://elbsolutions.com/chadtest to the almost final position of http://smartcar.websitewelcome.com/~wccogca . Since it was quite frustrating, I thought I would blog about it for other people who can benefit. Steps were:

  1. get temp website running moved over to final home (from http://www.elbsolutions.com/chadtest to http://smartcar.websitewelcome.com/~wccogca its temporary home before DNS change over)
  2. switch website completely to another (DNS change) and
  3. finalize the website at it’s new home in proper place (proper www address).  but the address will be http://www.wccog.ca – but the files in 2. are in the correct spot already.

With these ideas, I hope you can move your site over as well. Read the comments in the article by Rachel below – I think there are some even easier tools, but this one has some plugins and a theme that made this a bit of a pain.

If there is a typo, please comment so others can benefit from the corrections. It takes a second 🙂 Good luck.

So, first

  • do not use a text editor. Apparently there are some encoded versions of strings in wordpress, so there is a tool that I DID use at first, but following this article, by Rachel McCollin includes this tool by interconnect/it and that article is where the tip above is located.
  • Basically, I did not follow the article to the T – but it does not contradict anything.
    1. Copy over all your wordpress files.
      • I use cPanel, so to speed things up I zipped (compressed) the files
        • include the .htaccess
      • Then copy them to my local machine
      • Upload the zip file to the new location
      • UnZip the files on the new server.
    2. Turn off permalinks (to default) using the advice from the article by Rachel.
      • Remember the setting you had, as this will need to be re-enabled at the end of this exercise.
    3. On the old server, use phpMyAdmin, or some other way to archive the the wordpress database tables into an .sql file
      • it is ok to look at the .sql file, but don’t use a text editor to edit it – that is where I went wrong on the first go-rounds
    4. Make a new database on the new server. From this you will of course need
      • the database name
      • the username that is for this database
      • the password that is for this database
    5. Edit the wp-config.php file to point to the database on the new server, the new username and password
    6. Edit the .htaccess file and change the relevant info (most likely changing the directory used – so in this example, chadtest to ~wccogca
    7. Upload the files from step 1,4 and 5 to the new location. In this case, the new website
    8. Import the .sql file to the new server
    9. Download the tool from interconnect/it and put it in the root folder of your wordpress install next to the wp-config.php file. PLEASE RENAME IT NOW OR BEFORE UPLOAD to something someone cannot guess. Lets say “pinkalicious.php” because – who would use that?
    10. Rename the old directory (in this example, chastest) to something so that it cannot be used. If it is the root install, move the files TO another directory
    11. Clear your browsers cache especially as it points to the new or old site. Why? Do this because a true test if things are working will not be true unless fresh downloads of everything again.
    12. Now access this tool from interconnect/it via the internet  – so in this example, http://smartcar.websitewelcome.com/~wccogca/pinkalicious.php . Using the tool, I replaced the following strings – you have to do them all in this order – or the website won’t work.Notice that the order I listed above replaces larger strings first, then shorter ones with the same name or purpose. This is normal search and replace technique when you need to be geeky.
      • replace http://www.elbsolutions.com/chadtest with http://smartcar.websitewelcome.com/~wccogca
      • replace http://elbsolutions.com/chadtest with http://smartcar.websitewelcome.com/~wccogca
      • replace chadtest with ~wccogca
      • replace www.elbsolutions.com with smartcar.websitewelcome.com
      • replace elbsolutions.com with smartcar.websitewelcome.com (actually  – above we should have substituted @elbsolutions.com with @supercalagragalist, then at the end end, we would reverse that – this was added after the 1st part of the article was already finished – see below)
      • How did I figure all these strings out? Hard work – but the process involved downloading a new backup of the database over and over until strings like chadtest and elbsolutions did not exist in it any longer in the .sql file – now that WAS with a text editor. I used vi and notepad++ to edit the .sql file – it does NOT work – this technique used to work but no longer.
    13. Check out the new website. It should work
      • because I was a user, I had to edit my website and email as the tool was a little overzealous with elbsolutions.com
    14. Remove the tool that was placed there in the steps above that , in this example we called pinkalicious.php . This is because it quite dangerous and exposes your wp database password never to mention the whole database
    15. Log into the new site’s wordpress admin and turn on Permalinks again like you had them before
    16. Don’t delete the original files or the original database until it has soaked a long, long time. You might need something from it. Also save your backups in a safe spot.

Now I switched the DNS over and waited for a day. Then when I awoke, it worked – the website was at it’s proper place but lots of the links still pointed to http://smartcar.websitewelcome.com/~wccogca

So I started the search and replace tool – the same one above, so either http://smartcar.websitewelcome.com/~wccogca/pinkalicious.php or http://wccog.ca/pinkalicious.php would start it – since they are the same file in the same place. Actually I deleted the file in between -sessions as I tell my customers I am paranoid – so I had better practice that behaviour and I did (yes I am Canadian – so I spell word funny eh?)

Lets keep searching and replacing… but what? I will blog at the bottom to explain why I had to do more than I thought

  1. using an SQL tool, I downloaded a copy of the database and searched for ~wccogca and smartcar.
  2. I did this iteratively to find all occurrences, but here is the list of other things I had to search and replace
    • http://smartcar.websitewelcome.com/~wccogca replaced with http://wccog.ca
      • this is ideally all that should be required but…
    • smartcar.websitewelcome.com/~wccogca
      • just in case … I did this – 0 replacements
    • myemailaddress@smartcar.websitewelcome.com replaced with myemailaddress@wccog.ca
      • this was required because things were a little overzealous on the steps in the 1st half of the switch over – see text in grey above. Ideally I should redact the info above, but I will leaving for the teaching effect
    • mail.smartcar.websitewelcome.com -> mail.wccog.ca
      • we might as well use our own mail server now
    • smartcar.websitewelcome\\/~wccogca replaced with wccog.ca
      • ahhh- what is this? this is because the theme – and a famous plugin that a lot of people use (and the theme uses it in our case) HARDCODES THE WEB ROOT. ARRRRRGGGGG! Bad design. Oh well, it has to be replaced so lets stop complaining and get it done. 
    • \\/~wccogca\\/wp-content\\/themes -> \\/wp-content\\/themes
      • more junk left over due to hardcoding and used by the theme and layer slider – but this … no – it should not be necessary to replace but we have to since we find it
  1. Lastly, Remove the tool that was placed there in the steps above that , in this example we called pinkalicious.php . It is a super cool tool -but it exposes the password to all who look at it.