How to Move WordPress to Another Server

Moving WordPress to Another Server

One question often comes up at our WordPress Sydney and Dublin WordPress meetups.

How do you move WordPress to another server?

It’s easier that you may think and doesn’t require any programming.  You just need to follow a process.

Here’s the slideshare from the talk I recently gave at one of our WordPress meetups:

Now for the wordy explaination of the process on the slides:

Slide 2

This process will not work for any WordPress.com sites.

The reason is simple. You don’t have access to the php files nor the database (DB).

Slide 3

I belive that if you’re going to do stuff then you need to understand what stuff is made of.

A WordPress site is made up of two things  1) The Files – they do stuff 2) The DB – it stores stuff.

Together they make up a WordPress site and it is these two things you need to move and fiddle about with to replicate your WordPress site on another server.

Slide 4

Describes the process we are going to follow for the website files.

Essentially we are zipping up the files on the old server.  Downloading them to our local computer.  Uploading them to the new server. Then finally unzipping them on the new server.

Slide 5

We get the files from the old server first.

Here we introduct cPanel.  This is a popular interface that many web hosting companies use.  There are others like WHM but they all should have the same functionality.

If they don’t then it’s probably a good thing you are moving to a new hosting provider.We access cPanel for our old server and find the File Manager icon.

This will show all your website files.Navigate to where your root WordPress installation is kept.  If you are running WordPress from the root of your site, this will likely be in a folder called public_html or www.

Select all the files there, including the folders wp-admin, wp-include and wp-content.

From the top of the File Manager window select the option, Compress.  It may also be called pack, zip, bundle, squash etc.

This will produce a zip file in the same folder you are currently viewing.  You need to download this zip file to your local machine, either by using File Manager or your FTP client.

Slide 6

Here we reverse the prcess of step 6.Login to your new hosting cPanel and open up File Manager, navigating to your root folder (public_html, wwwetc.)

Upload the zip file from your local computer.  You may need to FTP this up to your host as most File Managers will have a limit on the size of zip files that can be uploaded.  FTP does not.

Once the file has been uploaded, using File Manager, select the zip file and find the unzip option.  You may need to right-click the file or select it’s checkbox and click on the option at the top of File Manager.  The option may also be called, unpack, uncompress etc.

Slide 7

Describes the process we age going to follow for moving the DB.

Essentially we are going to use a DB tool to export all the DB information in a format called SQL from the old server, fiddle about with the SQL file and then reimport it into a newly created DB on the new server.

Slide 8

On cPanel click on the phpMyAdmin link.phpMyAdmin is a tool for managing DB structure and content.Select your DB from the list and make sure that the WordPress tables are being shown and not the Info Schema.

Select the Export option from the top and click on Select All under the Tables section.

Scroll down to the bottom and click on Export.   This will open up a download dialog box.  Save the file on your local computer giving it an extension of .sql

Slide 9

Open up your SQL file on your local computer using a simple text editor that has a search and replace function.I used notepad on Windows.

Slide 10

Use the replace function of the editor.Replace your old domain name with the new domain name.  You can of course skip this step if the domain name is going to be the same.

It’s very important to get the correct format for this and to make sure that both the old domain format is matching the new domain format in the replace function.

So if your old domain is www.old-slow-site.biz and you are moving to www.new-speedy-site.com use the following format in the replace dialog.

Find what: http://www.old-slow-site.biz

Replace with: http://www.new-speedy-size.com

Make sure that if you use http:// at the beginning, you use it in both fields.  If you use a trailing slash at the end, use that in both fields too.

Replace all and save the file.

Slide 11

Exporting the SQL from an existing DB was easy but now we have to create a new DB and DB user on the new server before importing the data into it.Login to your new server cPanel select the MySQL Databases option.

Here you will be able to create DBs, DB Users and assign DB users to DBs.

Create a new DB leaving any options at their defaults.  Copy the new DB name somewhere, like notepad, as you’ll need this later.

Create a new DB User and give it a secure password.  Copy the new DB User name and password somewhere, like notepad, as you’ll need these later.

Now that your DB and DB Users are created you need to assign the DB User to a DB in order to give them access to it.
Use the Add User to Database option.

Slide 12

The new DB has been created and there’s a DB user who can access it.  Now we import the SQL data.Open up phpMyAdmin from cPanel on your new server.

Make sure the new DB is selected.  It should be empty and showing no tables or data.

Select the Import option from the top of phpMyAdmin.

Browse the SQL file that you downloaded and modified from your local computer.  Make sure the Format option is set to SQL and click on GO.

Your old DB data has now been imported into the new DB.

Slide 13

Now we bring it all together updating the WordPress configuration to point to the new DB and DB user.You’ll need to edit the wp-config.php file in the root of your WordPress site on the server.

You can edit the file on your local machine and FTP it up to the new server if you prefer but for this we’ll use the cPanel File Manager.

Open up File Manager fom the cPanel on the new server.

Locate and edit the file wp-config.php.  You may need to right-click the file or select it’s checkbox and click on the edit option at the top of File Manager.

Slide 14

There are definitely three and possibly a fourth line you will need to update in the wp-config.php file.Locate the line: define(‘DB_NAME’, ‘old_db_name‘);

Replace the old_db_name value with the new DB name you copied from slide 11.

Locate the line: define(‘DB_USER’, ‘old_db_user’_name);

Replace the old_db_user_name value with the new DB user name you copied form slide 11.

Locate the line: define(‘DB_PASSWORD’, ‘old_db_user_password’);

Replace the old_db_user_password value with the new DB user password you copied from slide 11.

Now depending on your new host, you may need to change the value localhost on the line: define(‘DB_HOST’, ‘localhost‘);

Most of the interner hosting companies I have come across use localhost as their machine name for where the DBs are located.  However some do not.

You will need to check with your hosting company and ask them which value to use here.  We know that Blacknight , for example, do not use localhost, rather they use specific machine names where the DBs are located on.

Save all your changes.

Slide 15

That’s it really.  See not too complicated after all.

If at this stage you are getting the error message “Error establishing a connection to the database” then either:

1) you have forgotten to assign the DB user to the new DB in slide 11 and/or
2) one of the four values you changed in the wp-config.php file in slide 14 is wrong.

If at this stage you are getting a “505 Internal Server Error” message then it’s likely your .htaccess file is not correct.

Edit this using File Manager and make sure there are no references to your old domain name, replacing them if they are.

Summary

Moving a WordPress site to another server isn’t that complex when you know what to do and follow a process.

About Wil

Wil is a professional web developer with a passion for leading edge technologies, security and server architecture. He spoke at WordCamp Sydney 2012, co-organizes the WordPress Sydney meetup, is on the sub-committee for WordCamp 2014 and contributes to the WordPress Core development. He likes pizza, sausages, chilies, beer, red wine and hyperdimensional physics.