It is a very common scenario to have to move a WordPress site across servers (when changing hosts for example) or to have to upload a “local” installation from your computer to a live server. In this quick tutorial we will look at how to backup and move a site from a user’s computer to one of our hosting packages but the same principles apply to server-to-server moves too.
Moving a WordPress site will involve the following steps:
- Back up files
- Export database from local server
- Upload files
- Create database on server
- Import database backup into newly created database
- Edit config file
- Run script to replace URLs in database
Back up files
The first thing to do before we move the site is creating a backup of the site’s files. This is not only good practice but it also gives us a backup of the site at that point in time, which could come in very handy in the future.
The most common way to backup files is simply to create a compressed “archive” using a popular tool such as zip. On most operating systems you can simply select all the files, right click (or control + click) on them and you should have options to “zip”, “archive” or “compress” them. This process should create a single archive file containing all of the site’s files.
Export database from local server
The easiest way to export a MySQL database is using the phpMyAdmin web based interface. phpMyAdmin comes as standard with most LAMP, MAMP and WAMP installations.
Open your local phpMyAdmin interface (normally found at a URL such as
http://localhost/phpmyadmin but this depends on your installation).
Select the database from the list on the left hand side. This will display the database structure. In the top menu select the “Export” tab. At the bottom of the export page check the option to save as file and compression, we recommend bzip2 compression for SQL scripts.
If you don’t know which database your WordPress site is using you can always check in the
wp-config.php file. In that file you will find a section like the following where you can see your database credentials (db host, db name, db user and db pass):
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', '[your db name]'); /** MySQL database username */ define('DB_USER', '[your db user]'); /** MySQL database password */ define('DB_PASSWORD', '[your db password]'); /** MySQL hostname */ define('DB_HOST', 'localhost');
Now that we have a full backup of the site (files and database) we are ready to start uploading to the remote server.
In this example I will use the hosting control panel’s “File Manager” to upload the archive we created in the first step and then extract it on the server. In the hosting control panel’s home page locate the “File Manager” icon and click on it.
Before we start make sure that your
public_html folder is empty. If there are any files you may want to remove them first. You can delete files by right clicking on them in the File Manager and clicking on the “delete” option.
Upload archive into
Once the archive is on the server right click on it and choose the option to “Unzip” it.
After the archive has been extracted right click on it to delete it as we don’t need it anymore and there is no need to keep it on the server.
Create database on server
In the hosting control panel click on the “MySQL Databases” icon under “Web Tools”:
In this screen you will be able to create a new database into which we will import your database backup. Choose a “username” and “password” and then click on “Create”.
Bear in mind that the database username (and database name) will have a prefix added. So after you have created the database check the resulting name. Scroll down the page and you will see an entry for the new db. You will need to remember this details for later when we edit the configuration file, so write them down.
Import database into live server
Now click on the “Manage” button next to the newly created database. This will open the phpMyAdmin interface in a new window. In the left hand side of the screen select the relevant database. In this exampe my database name is
Now click on the import tab:
Click on the “browse…” button, choose the file you exported from your local database and click on the “Go” button in the bottom right corner.
Edit config file
Now that we have created the database and imported the backup we need to update the WordPress configuration file with the new database credentials. In this example I will use the “Edit” function in the control panel’s File Manager to edit the file on the browser. You could always edit the file locally and then upload it via FTP.
Find the section with the MySQL settings and replace the username, database name and password with the details as shown next to your database in the control panel under MySQL databases. Note that the database name is the same as the database username.
Run script to replace URLs in database
Finally, if the site’s URL has changed (and in this example it would have), we will need to update all references to the old URL with the old host in the database. WordPress stores “absolute” URLs in the database and this could be very tedious, but we have put together a script to do exactly that. You can download the script here as well as instructions on how to use it. Note that you only need to download a single file called
Check that everything works
Browse your site and check that everything works.