How I Migrated a Website to a New Server – Part 2: Moving Website Files & Database

How I Migrated a Website to a New Server – Part 2: Moving Website Files & Database

How I Migrated a Website to a New Server – Part 2: Moving Website Files & Database

In Part 1, we prepared for the migration by creating backups, checking the server requirements, and making sure we had everything we needed.


In this guide,we will take the website files and database from the old server and restore them on the new server.


The old website will remain online while we prepare the new server.


What We Are Moving

A typical website migration involves moving two main things:

1. Website Files

These may include:

index.php
wp-admin/
wp-content/
wp-includes/
images/
plugins/
themes/

2. Database

The database usually contains things such as:

  1. Website content
  2. User accounts
  3. Settings
  4. Orders
  5. Comments
  6. Plugin data

For a WordPress website, both the files and database are required.

Moving only the files will not give you a complete copy of the website.

Step 1: Transfer the Website Backup

There are several ways to move files between servers.

One simple option is SCP, which securely copies files between Linux servers.

From the old server, you can run:

scp website-backup.tar.gz username@NEW_SERVER_IP:/home/username/

Let's break this down.

  1. scp — securely copies files
  2. website-backup.tar.gz — the backup we created in Part 1
  3. username — your new server username
  4. NEW_SERVER_IP — the IP address of the new server
  5. /home/username/ — where the backup will be placed

For example:

scp website-backup.tar.gz user@203.0.113.10:/home/user/

You will normally be asked for the password of the destination server.

Once the transfer finishes, log in to the new server and check that the file exists:

ls -lh website-backup.tar.gz

If the backup appears, the file has successfully arrived on the new server.

An Alternative: Using rsync

If you are moving a large website, rsync can be a better option.

For example:

rsync -avz public_html/ username@NEW_SERVER_IP:/home/username/public_html/

One advantage of rsync is that it can copy only files that need to be transferred, which can make repeated migrations or transfers more efficient.

For this guide, however, we will continue using the backup archive because it keeps the process simple.


Step 2: Extract the Website Backup

Now connect to the new server using SSH.

For example:

ssh username@NEW_SERVER_IP

Once connected, go to the directory where you uploaded the backup:

cd /home/username/

Extract the backup:

tar -xzvf website-backup.tar.gz

This will recreate the website files from the archive.

If the backup contains public_html, you may now have:

/home/username/public_html/

Check the contents:

ls -la public_html/

For WordPress, you should see files and directories such as:

wp-admin/
wp-content/
wp-includes/
wp-config.php
index.php

At this point, the website files are on the new server.


Step 3: Create the New Database

The next step is to recreate the website database.

If you are using cPanel, go to:

cPanel → MySQL Databases

Create:

  1. A new database
  2. A database user
  3. A strong password

Then add the user to the database and give it the required privileges.

For example:

Database: newuser_website
User: newuser_dbuser
Password: ********

Keep these details safe.

We will need them when connecting the website to the new database.


Step 4: Import the Database

Remember the database-backup.sql file we created in Part 1?

Now we need to import it into the new database.

If the SQL file is already on the new server, you can use:

mysql -u DATABASE_USER -p DATABASE_NAME < database-backup.sql

For example:

mysql -u newuser_dbuser -p newuser_website < database-backup.sql

Enter the database password when prompted.

If the command finishes without an error, your database should now be restored.


Step 5: Connect the Website to the New Database

The website needs to know where its new database is located.

For WordPress, open:

wp-config.php

You can edit it using:

nano wp-config.php

Look for:

define('DB_NAME', 'old_database');
define('DB_USER', 'old_user');
define('DB_PASSWORD', 'old_password');
define('DB_HOST', 'localhost');

Change the database details to the ones you created on the new server:

define('DB_NAME', 'newuser_website');
define('DB_USER', 'newuser_dbuser');
define('DB_PASSWORD', 'NEW_PASSWORD');
define('DB_HOST', 'localhost');

Save the file.

Important: Never publish your real database password in screenshots, tutorials, or public repositories.


Step 6: Check File Ownership and Permissions

Your files may now be in the correct location, but the server also needs permission to access them.

First, check the ownership:

ls -la /home/username/public_html/

If necessary, ownership can be corrected.

For example:

chown -R username:username /home/username/public_html

However, permissions vary depending on your server configuration.

If you are using cPanel, avoid changing permissions unnecessarily. The hosting environment may already have the correct ownership and permissions configured.


Step 7: Test the Website Before Changing DNS

Do not change your DNS yet.

The new server should be tested first.

Depending on your setup, you can test the website using:

  1. A temporary URL
  2. A temporary domain
  3. A hosts-file override
  4. Your hosting provider's preview/testing tools

Check the important parts of the website:

  1. Homepage
  2. Internal pages
  3. Images
  4. Contact forms
  5. Login
  6. WordPress dashboard
  7. Plugins
  8. Themes
  9. Search
  10. Downloads
  11. Database-driven content

If it is an online store, test the important shopping and checkout functionality as well.

The goal is to make sure the website works on the new server before visitors are sent there.


Common Problems at This Stage

Database Connection Error

If you see:

Error establishing a database connection

check:

  1. Database name
  2. Database username
  3. Database password
  4. Database host
  5. Database user permissions

403 Forbidden Error

A 403 error may be related to:

  1. File permissions
  2. File ownership
  3. Web server configuration
  4. .htaccess

Check the server configuration before making major permission changes.

500 Internal Server Error

A 500 error can happen when the new server uses a different:

  1. PHP version
  2. PHP extension
  3. Web server configuration
  4. .htaccess configuration

Checking the server error logs is usually the best way to identify the cause.

What We Have Accomplished

At the end of Part 2, we should have:

  1. Website files transferred
  2. Website files extracted
  3. New database created
  4. Database imported
  5. Website configuration updated
  6. File ownership checked
  7. Website tested on the new server

Most importantly, the old website is still online.

We have prepared the new server without changing where the domain currently points.


In Part 3, we will take the website live on the new server.

We will cover:

  1. Setting up SSL
  2. Final website checks
  3. Updating DNS
  4. Understanding DNS propagation
  5. Monitoring the website after the switch
  6. Checking for broken pages and errors
  7. Taking a final backup
  8. Knowing when it is safe to shut down the old server

This is the stage where we finally point the domain to the new server.

Continue to Part 3

How I Migrated a Website to a New Server – Part 3: Testing, DNS & Going Live

Comments

Oops! This post doesn't have any comment currently.

Leave a Reply

Your email address will not be published. Required fields are marked *

Quick Enquiry