If you’ve used WordPress before, you have probably quickly figured out that there’s no built-in way of moving or migrating a website to a new server or domain. In fact, many web designers and developers simply try to move the files and database over to a new server and think it will magically work, but you’ll most likely be greeted by Internal Server Errors due to a misconfigured .htaccess file or mysterious redirects to your old domain or website.
The solution to this problem will vary depending on whether you’re moving to a new server but keeping the same domain name, or if you’re moving to a completely new domain as well.
Moving to a New Server
If you just need to move your website to a new server while keeping the same domain name, then the process is fairly simple. You will first need to copy the database, and then move over the files with a file manager or FTP.
- Export the Database
First we need to copy the database. The easiest way to do this is to login to your cPanel account and click on phpMyAdmin. That will take you to phpMyAdmin, which is the database management tool.
Next, select your database from the list of databases in the left sidebar and then click on the Export tab at the top of the page.
The options to select are as follows:
- Export Method: Custom
- Table(s): Select All
- Output: Save output to a file
- Output Compression: gzipped
Then click the Go button at the bottom of the page, and your database download should start any second.
- Import the Database
Next we need to take the database we just exported and import it into our new web host server. To do this, start by logging into the new cPanel account and creating a new database using the MySQL Database Wizard tool.
Write down the database name, username and password as you will need it later in order for your WordPress website to connect to it.
Then we’ll proceed by going into phpMyAdmin again (this time on our new server). You will select the database from the left sidebar again, and then click on the Import tab at the top instead.
The next step is pretty straightforward, you just need to browse your computer for that database file we exported, and then click the Go button.
After a few seconds, you should get a confirmation that your database has been successfully imported.
- Move Files with FTP
Now that the database has been successfully moved over, we need to do the same for files. There’s many ways of moving files from one server to another including file manager, FTP, SSH, and so on. For our sake, we’ll use the FTP method since it’s a fairly standard way of uploading and download files between a computer and the server.
The best way of doing this is to create a new folder on your desktop, then login to your old web server via FTP using your favorite FTP client such as Filezilla (for Windows) or Transmit (for mac).
Then go into your public_html folder and simply select all files and folders and download them into the folder you created on your desktop.
Once the files have been downloaded, log out of that FTP connection and login to your new server’s FTP. Then you will go into public_html folder again, and this time, upload all the files from the folder on your desktop.
- Change WordPress Database Credentials
Once the files have been uploaded, you only have one last step to do and that is to change the database credentials.
So open the file wp-config.php and change the 3 values: DB_NAME, DB_USER, and DB_PASSWORD. Once you change those and save the file, go to your domain to verify that it is all working fine.
Note: If you have not yet changed the DNS settings on your domain to point to the new server, you will want to do that right now.
Moving to a New Domain Name
The process of moving to a new domain name is a bit trickier because WordPress database has many instances where the domain name is stored. Without changing all those records, the migrated WordPress website simply would not work as desired.
There’s two ways to copy the website over: using a backup/migration plugin or manual migration similar to the one mentioned earlier in this article.
Using a Backup or Migration Plugin
The quickest and safest way to migrate a website to a new domain is to use a plugin. The two best ones I’ve used include Duplicator and BackupBuddy. For the purpose of this demonstration and because my BackupBuddy license has expired and I only have an old out-dated version, I will use Duplicator, which is free.
- Install Duplicator Plugin
The first step is to install the Duplicator plugin from the WordPress repository.
- Create a “Package”
Go to your WordPress admin section and in the left navigation bar, click on Duplicator.
On the Duplicator Packages page, click on Create New button. This is where you will select all options such as excluding certain database tables or files from being included in the backup.
- Build the Package
Once you have selected all the options, proceed to building the package. This will output the database and zip up all the files.
Once the package is built, you will be given the option to download both the Installer and the Archive file. Download both of them as we will need them in order to restore the website on the new server.
- Restore the Package
The final step is restoring the package on the new server. We will do that by first uploading both Installer and the Archive file into the root of our new web host. If you want to move the website into a folder instead, this is the time to do it.
Once the two files have been uploaded, the next step is to go to your website URL and access installer.php. (For example: www.domain.com/installer.php)
If you have not already done so, you will need to create a new database or at least have the database user’s username and password ready so that the installer can create the database automatically for you.
Follow the steps in the Installer to restore your website. Once it is complete, you should thoroughly test your website and make sure everything is as it should be.
Manual Migration
The manual migration will be identical to the “Moving to a New Server” part we went over earlier, except after we export the database, we will need to do a Find and Replace for the old domain.
Running Find and Replace on the Database
To avoid any serialization issues, we will run the Database Search and Replace Script in PHP. To start, simply go to that website and download the script.
Once you have it downloaded, you will upload it to the same location where you uploaded the new website.
Then we are ready to run this script by going to it in the browser, such as www.newdomain.com/Search-Replace-DB-master/. When you get there, you will be greeted with a page similar to the one shown below.
If it was able to successfully find your wp-config.php file, then it most likely auto populated the database name, username, and password fields. If it has not, then you will need to manually enter those.
In addition, you will also type your old domain in the replace field and old domain in the with field.
When you’re ready, click on the dry run button which will first do a test run. If everything looks good and there aren’t any errors, then you can proceed with a live run. This will make permanent changes to your database.
Once it has run successfully, you are ready to look over your website to make sure everything is correct. If everything went as planned, you should be ready to use your website on your new domain right now.
Conclusion
As you can see, there are many ways of moving a WordPress website from one server to another, even if you have to change the domain name. Although there are many ways of doing it, usually it is not well documented and new developers or web designers often run into problems with WordPress migrations. That is exactly the audience for which this guide was written.
So what is your favorite method of moving a WordPress website? Is it included in this article? Let us know about it in the comments.