Tuesday, July 28, 2015

Tutorial - How to migrate WordPress website (The proper way!)

Hello kiddos!

    Today we will learn the proper way to migrate a WordPress website from one hosting to another. Not that method that teaches you to install fresh WordPress installation and to move few folders from the old hosting on top of it. This is not the proper way to migrate a website and can mess everything.

    I will also try to keep it as simple as possible and will not involve complicated SSH command lines. Using SSH will save you a lot of time and efforts but it's more for the hosting support professionals than WordPress newbies. I will assume that if you know how to use SSH you will find your way to optimize this process ;)

Just to be clear:

DB = Database

Before starting the migration!


Let's prepare few things, shall we?

If you haven't done it already, download FileZilla - Good FTP client. We will use it to transfer files and folders.

Get access to FTP/SFTP and phpMyAdmin to both hosting environments - mandatory.

Add the website into the new hosting. This depends on the hosting environment and if you are not sure "how to" just ask the hosting support.

Putty or ZOC terminal emulator is optional.


Let's begin with the migration!


1) Download the files via FTP from the old hosting:

By using FileZilla connect to the FTP server of the old hosting and download all website's files to your computer.

Tip: You can reduce the download and upload time by putting all of the files in a archive.
Tip: Make sure that you have enabled "Force showing hidden files" in FileZilla. The option is located in: Server > Force showing hidden files.


2) Upload the files via FTP to the new hosting:

Again using FileZilla connect to the new hosting FTP server. Locate the website's directory and upload the files that you have already downloaded from the old hosting.

Tip: Check if you have moved the .htaccess file. Some users make custom rules there and it might be mandatory to move it.
Tip: Sometimes you will need to press F5 to refresh the folder and see any new files.

3) Export the Database from the old hosting:

Open phpMyAdmin. Locate the database and click on it. Go to the upper menu and click on the export option. Then click on Go.

Tip: If the Database is too big (more than 128-256MB you should ask the hosting support to export it for you via SSH (or use their Database backup solution). WP Plugins are often unreliable for that.

4) Check for old absolute paths in the DB: 

Some plugins leave absolute paths in the DB and if you leave them this can lead to crashing of the website or at least performance issues.

Tip: You can download the DB and search and edit with Notepad++, gVIM or similar text editor.

Look for paths like this: /home2/userTest/public_html/wp-content/....

Replace before "wp-content" with the correct paths of your server. If you are not sure what are they consult your support or developer.

Tip: If you have moved your website to a different domain you should edit it and replace every old domain with the new one in it! This can be achieved by downloading the DB and edit it using Notepad++, gVim or similar text editor (just find and replace). In 99% of the cases this will be enough.



5) Import the Database to the new hosting:

We will need to configure and tune the website to work with the new hosting environment. I will assume that you have already created DB, DB user and DB password.

Open phpMyAdmin. Locate the database and click on it. Go to the import option on the upper Menu > "Browse" the files that you have just exported in your computer and upload it.

Tip: Again! If the Database is too big you should import it via SSH or ask the Hosting support to do it for you.

6) Locate the wp-config.php and edit it:

- Fill the credentials of the new environment - DB name, DB user, DB pass:

/** The name of the database for WordPress */
define('DB_NAME', 'fill_the_db_name');

/** MySQL database username */
define('DB_USER', 'fill_the_db_user');

/** MySQL database password */
define('DB_PASSWORD', 'fill_the_db_password');

/** MySQL hostname */
define('DB_HOST', 'localhost'); //in 99% of the cases you should leave this as it is

- Change the paths if there are any in the wp-confg.php file according to the new hosting environment;

And now the fun part!


The final tuning!


7) Check for any errors in the error's log:

You can have some minor issues with the new environment. Every hosting environment is different and if you can't clean the errors alone the hosting support should help you.

Optional but recommended!


8) Check your file's permissions: 

If you have access to SSH run the following commands IN public_html:

find . -type d -exec chmod 755 {} ;
find . -type f -exec chmod 644 {} ;


If you are moving your website from WPEngine is little more complicated. and it's part of another tutorial.

Tip: I'm not recommending the usage of plugins to migrate websites. If you want to do it right do it manually.
Final Tip: If you are not sure what are you doing just hire a professional to do it for you ;)

3 comments:

  1. Whoever might be following this guide, do know that the step of replacing the serialized strings containing the URL of the site safely is missing and you might end up with some problems you could have avoided otherwise. That's concerning the tip on step 4. Hopefully the author will have the time to update the article soon :)

    ReplyDelete
  2. Hello Шемет,

    You need to replace old URLs only if the website is moved to a different domain. There was a "tip" for that at the end but it was obviously on the wrong place.

    The last part for the URL replace was moved between the export and import parts and the "tip" for the URLs also (point 4).

    Thank you for your advise!

    ReplyDelete