WordPress GuideHosting → Migrate to New Server

Migrate a WordPress site to a new server

Woman Coding on Computer

While most hosting companies provide migration services, you cannot control the process, and ensure everything is moved over to the new server correctly. You may also notice that your website is not working as expected after the migration, and it’s hard to understand what exactly went wrong.

You are the one who knows how your website is built, so knowing how to perform a WordPress migration manually can save you time and money. So, let’s review the process of moving a WordPress site to a new server in a comprehensive, step-by-step manner.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

Overview of moving a WordPress site to a new server

Moving a WordPress site to another server is pretty straightforward and does not require much time and effort, but it has important nuances. In short, migration means taking a backup of your WordPress website and then restoring it manually on another server. The only difference between the processes of restoration and migration is that you may need to set up the necessary infrastructure on the destination box first before you can get your website correctly imported there. We will review the whole process to ensure that no issues arise after your WordPress website has been migrated.

WordPress migration steps

The process of moving a WordPress website to a new web server consists of seven main steps:

The fifth step may be the most important, as just restoring the backup you took does not always lead you to success. Due to the changes in the hosting environment, including the web server and database management system configuration, you can run into technical issues of different kinds. It’s vital that you take all configuration details of the new server into consideration and strictly follow the steps outlined below.

Warning about the site downtime

Another significant thing to remember about any website migration is downtime, as it is inevitable in any case. When moving a WordPress site to a new server and pointing DNS records to it, your website may undergo some changes that will be lost once you switch to the new server. DNS propagation alone can take up to 48 hours, plus the migration process. Ideally, you would want to put your website into maintenance mode, but it will mean more downtime.

When an expert from a hosting company performs a migration, all data is actually copied to the new server twice. First, we transfer everything to the destination server and ask you to test whether your website works correctly from it. There is no downtime during the initial sync.

Then, after you have confirmed there are no issues with the website functionality on the new box, we perform the final sync — we transfer everything that has been changed on the website while it was still live on the old hardware to the new server, so no data is lost. After that, we update DNS for the website to resolve to the new server.

Ultimately, if you own a vast website that undergoes many changes daily, we strongly recommend you delegate the migration to the experts.

Step-by-Step: moving a WordPress site to a new server

Let’s dive into moving a WordPress site to another server in just seven simple steps. They are lists in sequence in the sections that follow.

1. Taking a backup

The first thing we must do is take a backup of our WordPress website on the source server, both the website files and the database. We will use the WordPress Command Line Interface (WP-CLI) and the tar utility in this article.

WordPress database backup

To create WordPress database backup, we will be using the WP-CLI utility, so you will need to navigate to your WordPress website installation directory and be logged in as the account owner. Next, run the wp db export command choosing the name of the database backup. You can specify the directory you need to save the dump to. Here we will save it to our website’s document root directory to then include it in the archive with the website files:

WordPress files backup

Navigate to the parent directory of your WordPress installation. It means we need to move one directory higher than the one where we keep our website files. Again, you need to be either logged in as root or the owner of your website account.

Create a tar.gz archive of your WordPress website, like shown below. The flags we are using are:

Once the backup is saved, you will see it in the directory you ran the command from. Here we saved it to our website’s parent directory or the Linux user’s home directory. It will include the database backup as well as what we saved in the html folder.

2. Preparing the new server after analyzing the plan and setup requirements

When preparing for the move of a WordPress site to a new server, we first need to ensure an account for it is created there, including having a new blank database and a database user with all necessary permissions granted. The process is similar for all control panels and managed hosting dashboards.

With regard to these preparations, the type of hosting plan you have with Liquid Web in terms of both the old site and new site need to be analyzed for this effort. Below are the kinds of details to access prior to setting up the new server:

You may also need to tweak the configuration on the new server, including the chosen PHP handler, the webs server, and the database management system settings.

You can skip this step if we already have an account on the new server, for example, if you would like to migrate the staging version from the staging environment to the production server.

3. Importing a backup

We can always just download a backup from the source server to our local computer and upload it to the destination box, but a better solution would be to have it transferred to a new server directly. We can do that using the rsync utility. To successfully import the backup, we created to the new server, we need to be logged in via SSH as root or the new account owner on the destination box. We need to have either root or the old user account SSH credentials for rsync to make a connection to the source server and import the archive.

In the example below, we are transferring the website_backup.tar.gz archive we created in /var/www/wordpresstest.com to the /home/wpsite/ folder on the new server. We are connecting to the source server as root via SSH. Please note that our source server has a non-default SSH port of 2254. The default SSH port is 22, but server administrators tend to change it for security reasons:

The archive we downloaded will be owned by the user we were logged in to on the new server. In this case, we were logged in as root. So, if we keep working as root on the new server, we do not need to change the file’s ownership:

4. Restoring from a backup

Now that we have imported the backup we took previously to the destination server, it’s time to extract the files from the archive and import the database to restore the website.

WordPress files restoration

To decompress tar.gz archives, we can use either tar or gunzip commands. If our destination directory is empty, we can extract our files there directly. Here we created a new public_html_new directory to restore the site to it first:

Then we use tar to extract the files from the archive to public_html2. We are using the following flags:

The — strip-components 1 element we added means we are extracting our website files to the new directory skipping the original folder we archived. If we do not use it, we will find the html directory we archived originally in the public_html_new folder:

If we want to preserve the old content the account had, we can move the existing public_html folder, as shown below. Then we just move the newly extracted content to our website’s document root directory:

Please note that if you are working from root, you will need to change the ownership of the files to your account user, which in our case it is the user wpsite.

WordPress database restoration

We saved our database backup to the archive, so now we will see it in the website’s document root directory. We can use WP-CLI to restore it. But before doing it, we need to modify our wp-config.php file to include the new database name and user credentials. We can edit the file from the File Manager interface or the command line using the preferred text editor or WP-CLI.

The wp config edit command launches the system editor and allows you to change the contents of the wp-config.php file. You will typically need to update DB_NAMEDB_USER, and DB_PASSWORD. You may also need to change the local hostname and the database table prefix:

After we have modified the wp-config.php file to reflect the new database information, we can import the backup we took. If you want to remove any existing data from the database first, use the wp db reset command:

5. Making changes to the website configuration

Depending on our goals and the new hosting environment we migrated our website to, we may need to change the website or server configuration. For example, we may need to perform a search-replace step on the database if we migrated our WordPress website to use another domain name, reset permalinks, or change the database prefix.

WordPress wp search-replace command

You can perform a search-replace on the database using the wp search-replace command provided by WP-CLI. We recommend using –dry-run to preview the changes without saving them to the database:

Once you have confirmed you would like to apply the changes, run the same command without the –dry-run option.

WordPress permalinks reset

We can reset the WordPress rewrite rules using the wp rewrite flush command provided by WP-CLI.

WordPress cache purging

A situation may arise where you must flush the WordPress cache, especially if you are moving a website to replace an existing installation under another domain name. The WordPress Command Line Interface also allows us to flush the object cache using the wp cache flush command:

6. Testing the WordPress website

Testing is an integral part of the migration process that allows us to confirm that everything is working correctly after moving a WordPress site to a new server. We strongly recommend not skipping this step, as it’s best to ensure your website works as intended before updating DNS. Using a hosts file is a great way to preview a website from the new server.

7. Changing DNS records

Updating records in your DNS zone is the final step in moving a WordPress site to a new server. Once everything looks perfect on the destination box, you can point your domain to the new IP address. Please note that DNS changes can take up to 48 hours to propagate fully, so we recommend making them during off-peak hours.

8. Cleaning up files used for the site move for security reasons

We would recommend including a final step when finished with a site migration for deleting the tar.gz backup file and the MySQL dump file. If you need to keep those files, we highly recommend moving them out of the public_html folder for security reasons. It is not a best practice to keep backup files in the public_html folder of the site server.

In fact, the least amount of time you keep backups in the public_html folder on your site, the better — for data exposure and security risk reasons. Ideally, you should pull down the backup file from any public access point as soon as possible and import it locally. If you do not remove the backup from the public_html folder on your site, you have made finding the list of users that exist in the WordPress site’s database very easy for hackers to find.

Ready to get started?

Get the fastest, most secure WordPress.org hosting on the market.

Additional resources

What is managed WordPress hosting? →

Get details and decide if managed WordPress hosting is right for you.

What is managed WordPress hosting? →

Whether you’re a blogger, small business owner, or aspiring entrepreneur, chances are you’ve heard of WordPress. It’s a great tool for building your online presence, but it requires web hosting – which can be tricky if you’re not familiar.

A complete guide to WordPress shortcodes →

Shortcodes make life easier. Learn how to get started!

Kiki Sheldon works as a Security Specialist for Liquid Web. Before joining the Abuse & Security Operations Department, she worked on the Liquid Web Managed Hosting Support Team, where she gained extensive knowledge of Linux System Administration and popular Content Management Systems (CMSs). Kiki’s passion for writing allows her to share her professional expertise and help others. She keeps up with technology and always looks to improve her technical skills. In her free time, she enjoys reading, especially classic books and detective stories.

Trust us to help you choose the ideal hosting solution

Loading form…