Moving wordpress site to a new server

Moving wordpress site or  any other site requires transferring atleast below mentioned files and settings to the new server

  1. Code and Media files residing in your public_html directory
  2. Database
  3. Cron Jobs
  4. Any Back up scripts or other shell scripts, snippets, config files, etc residing outside your public_html directory

Some hosting companies like Siteground also provide free website transfer. However for number of reasons like complexity or security you may decide to perform the migration yourself.

Below steps explains moving wordpress or any site from one server to another without using FTP or without requiring to download an upload files on your PC.

Here are the steps for moving wordpress site

1. Clean up your old server and remove any unnecessary files or directory

2. Create a tar file from the entire public_html directory contents

SSH to your legacy server and run below command

3. Create an SSH key

To accept data from the legacy server, an SSH key from the legacy server is required to be added to the known hosts file on the new server. This key can be directly appended to the text in the known hosts file if you have access to it or some hosting providers provide a panel to add the key and to restrict the connection from certain IP addresses. Here you can provide the legacy server IP address.

The above command will generate dsa key. You can create either RSA or DSA key. Some hosting companies only accept certain type of key.

After running the above command the key will get created in your .ssh directory. Copy the contents of the public key and add them to the new server to accept connections from the legacy server

4. Moving wordpress public_html folder contents

Above command will copy the public_html contents from the legacy server to the new server’s public_html directory. You will required to Unarchive the contents on the new server.

5. Export database on the legacy server

Here you can use utility of your choice or you can just create a mysqldump of your database. If you are using some utility like SXD then create a copy of database on the legacy server using SXD.

Then move the database to the new server using below command

6. Import the database on the new server

First create a blank database on the new server and then import the database. If you have database backup created using SXD then install SXD on the new server and import the database on the new server through SXD.

7. Other Data (outside public_html)

If the data is not too much you can just tranfer this data using FTP or follow the same process as explained in Step 4

8. Cron Job

Lastly create similar cron jobs on the new server and check if they are working

 

Importing SSH key into keychain on Mac

Importing an SSH key to your keychain on Mac allows you to login without entering your passphrase each time.

This helps if you are a developer and require to commit your changes to the server quite frequently.

Here are the steps

  1. If you have a Cpanel on your server, login to your CPanel
  2. Generate an SSH Key (choose a suitable passphrase while generating the key and make a note of it)
  3. Once the SSH Key is generated, Authorise the key
  4. Download Private and Public keys and copy both the keys to your ~/.ssh directory
  5. Change permissions on both keys, Remove staff, everyone no access, Admin read write
  6. Open terminal and run: ssh-add -K ~/.ssh/KEY_NAME
  7. When prompted enter passphrase used while creating the key