This is not as hard as you may think, there are a few basic steps required and as long as you follow them you should be able to move your WordPress site quickly, as with all migrations it’s best to look at what you have and work out a plan of action before starting and always make sure you have a decent backup of all your data including your database.

Scenario

Here I am going to detail how to migrate using the same domain name, if you want to change the domain or location then some modifications will be required, you can find details on this from the WordPress site directly or read another of my posts​ when I get round to writing it.

Here I will be migrating a site to between 2 servers old server (10.10.10.10) and new server (10.10.10.20).

I should also point out that you don’t have to do this by hand as there are plugins that do this for you, and if you are using Plesk Onyx and have the WordPress toolkit V2 then this also has the ability to move your WordPress site.

What You Need

  • FTP/SSH access to the hosting space on both servers.
  • Access to the WordPress database
  • Access to your domains DNS records to make changes.

Preparation

When moving you site it’s best to make sure you have time and are not adding any new posts as this will cause the data to become out of sync and possibly cause problems down the line.

You need to make sure you can FTP or SSH to both server, you can access the database and dump/export it from the original server, have the ability to create and import the database on the new server, you should create the database ready for an import if this has not already been done.

Once you are happy that you can do all of this then you are ready to start the migration of your site.

Starting The Migration.

FTP Migration
  1. Login to the original server and download all files to a folder on you local desktop.
  2. Login to the new server and upload all the files you just downloaded.
  3. Export your WordPress database from the original server
  4. Import your​ database on the new server.
  5. If you database details are different from that of the original server (they probably are) then you will need to edit your wp-config.php file this will be a simple edit where you update the database details.
  6. Check file permissions some files and folders may need to have the permissions updated as they will have been lost during the FTP transfer process.
  7. Update the DNS for your domain to point and the new server
  8. Once DNS propergation has completed you should now be able to access the site on the new server and continue to post as you have done in the past.
SSH Command Line Migration

This is a little more complex but this is my preferred method when available.
When transferring by SSH there are a few things to consider and check before you start.

  1. Do you have SSH access to both servers, and can you SSH into the new server from your old server?
  2. Will you be transferring files as root/admin or as the site user
  3. What tools you have available to you (rsync/scp)

I am going to asume that here that all sites run as there own user and you are transferring the site as the root user although that may not be the case for your self and the commands you would use may need a small tweek.

Transferring The Site Files
  1. Login to the original server and locate where your site files are stored, most server will be /var/www/something/something in this case the files are going to be in the same location on both servers /var/www/vhosts/domain.tld/httpdocs/
  2. The first thing to do is transfer your site files to the new server, I normally use rsync as this will allow transfer to continue if the interrupted for any reason.
    rsync -avP /var/www/vhosts/domain.tld/httpdocs/ 10.10.10.20:/var/www/vhosts/domain.tld/httpdocs/
  3. After your site files have been transferred you can now export your database and import this into the new server

Export Database

mysqldump -h'10.10.10.10' -u'your-db-username' -p'your-db-password' database-name > database-name.sql

Import Database

mysql -h'10.10.10.20' -u'your-db-username' -p'your-db-password' database-name < database-name.sql
  1. If your database details are different from that of the original server (they probably are) then you will need to edit your wp-config.php file this will be a simple edit where you update the database details.
  2. Check file ownership on the new server if transfered as the root user then this will probabily need to be changed so you will need to change the ownership with chown
    chown -R user:group /var/www/vhosts/domain.tld/httpdocs/*
  3. Update the DNS for your domain to point and the new server

Once DNS propagation has completed you should now be able to access the site on the new server and continue to post as you have done in the past, the nice thing with doing this by ssh is you have the ability to copy the site and if you find that a user has made changes or uploaded more content you can just use rsync to recopy the data that has changed and export import your database quickly without the need to make a local copy of all files which can save a lot of time especially if you are migrating a large site.

Exporting Your Database

If you don’t have access to your database on the original server then this script can be used to export the database and download it to your hosting space or desktop, simply create a new file on the original hosting in you WordPress directory dbdump.php then past in the contents, once done navigate to it in your browser.

Database Dump Script

<?php
include 'wp-config.php';

$DBHOST=constant("DB_HOST");
$DBUSER=constant("DB_USER");
$DBPASSWD=constant("DB_PASSWORD");
$DBNAME=constant("DB_NAME");

echo 'Database Hostname: '.$DBHOST.'</br>';
echo 'Database Name: '.$DBNAME.'</br>';
echo 'Database User: '.$DBUSER.'</br>';
//echo 'Database Pass: '.$DBPASSWD.'</br>';
$date = date("Y-m-d_H-i");
$file = $DBNAME."_".$date.".sql";
exec("mysqldump -h'$DBHOST' -u'$DBUSER' -p'$DBPASSWD' '$DBNAME' > '$file'");
echo "<a href=\"$file\" download>$file</a>";
?>

Add a comment

0.0(0 votes)

Next Post Previous Post