Like many web professionals, I’m so busy doing things for clients that it’s true to say that my own site often suffers thanks to a lack of time. One thing that I have been meaning to do for some time is move the site, which is a WordPress site, to another server, as I’m not overly happy with my current hosts.

However, it’s one of those things that I’ve put off doing because it does just seem like a lot of hassle, especially since my theme is bespoke and therefore any issues and it will take time to do again (yes, a simple backup will take care of this, I know).

Bearing all of that in mind, I can imagine that many people have the same problem, or have no idea where to start, so here you will find instructions on how to carry this out, without losing theme elements or ending up with a site full of broken links.

Keeping the same URL

Firstly, it’s worth noting that if you haven’t really optimized the site and intend on keeping all of the URLs, and the domain name and the database is going to remain the same, then it’s a simple process.

If this is the case, then you will just have to copy the files and database across to the new server. If you want to change the name or user of the database you will have to alter the edit.wp-config.php file to ensure that it has the right values. Locate the following in the root folder and alter accordingly.

define('DB_NAME', 'user_wrdp1');
/** MySQL database username */
define('DB_USER', 'user_wrdp1');
/** MySQL database password */
define('DB_PASSWORD', 'password');

If you’re changing server but keeping your domain name, then you will need to edit wp-config with your new database and user details and then just upload all of your files to the new server.

It’s pretty obvious too, but bears repeating, that you should make a full backup of the site, which should include the following:

  • Plugins
  • Theme files
  • Any uploads that you’ve made
  • The database

To do this, you can use phpMyAdmin, which is an open source tool for managing MySQL databases and includes a wealth of useful tools. You can choose to export data in a number of formats, such as CSV, SQL, XML, PDF, ISO/IEC 26300 and others. Alternatively, you can use a plugin such as WP-DB-Backup.

Uploading from local to a remote installation

Once you’re fully backed up and ready to go, first of all you’ll need to disable Permalinks. This can be done in the “Permalinks” screen view which is in the “Settings” menu. Choose the default setting and hit save.

permalink settings

Then, if you haven’t already, backup the database, make a copy and rename it.

Installing WordPress on the new server

Install WordPress as you normally would, either using FTP or through cPanel and then copy all of the files from your local wp-content file to the one on the server using FTP or SFTP. Next, you will need to edit the database in order to replace the local URL with the remote one.

For this, use a search and replace utility, preferably not a text editor and change every instance of the local URL to the remote one. You can use SEARCH REPLACE DB for this, which should be installed in the root folder of your WP install for best results. In order to protect the script from abuse, it’s best to rename it before doing anything else.

For example, if you rename it newinstall.php, you will then go to http://yoursite.com/newinstall.php and follow the on-screen instructions to carry out search and replace. Once you’ve finished doing this, it’s important that you also delete the script in order to secure the DB.

Save the database before continuing. If a new database has been created when you installed WP, then this will need to be deleted. You can do this by:

  • Using phpMyAdmin, click on the “Structure” tab
  • Underneath the list of tables click on “Check All
  • Choose “Drop” from the menu called “with selected
  • Choose “Yes” when the message pops up asking if you want to drop all tables
  • Re-enable your permalinks as you had them in the last installation

phpMyAdmin

You’re good to go.

Moving from host to host

If you’re moving the site to a new host, it’s exactly the same as when you upload from a local server, with one key difference being that you will have to download all of your files from the existing host using FTP.

Changing the URL

If you need to change the URL of the site as it’s in a subdirectory or it’s a new domain name, you can do this by adding some lines to the functions.php file of the theme, as below.

update_option('siteurl','http://www.new-site-address.com');update_option('home','http://www.new-site-address.com');

Then, load the new files onto the site and it should work fine. Don’t attempt to just copy all of the files and database over, as this won’t work properly and you’ll end up with broken links.

Once you’ve then loaded the new files, test and delete the lines from the functions.php files, as your new settings will now be stored and saved in the database.

If you need to set up 301 redirects, which is important to both search engines and users, then you’ll need to connect to the old site and edit the .htaccess file. Locate the file and then paste this code at the top of the file:

1 #Options +FollowSymLinks
2 RewriteEngine on
3 RewriteRule ^(.*)$ http://yoursite.com $1 [R=301,L]

Once you’ve done this, go back to the new site and test to ensure that the changes have been made successfully. It’s also a good idea to submit the change of URL to Google via Webmaster Tools and you will also need to verify it.

Finally, once you’re confident that all is working well and you’ve checked and tested, remember to tell the site users about the change. You can do this in whatever way you think will be the most effective, by newsletter, blog post or on social media and if you still own the old domain, you can set up a temporary redirect to catch any that initially fall through the net.

That’s it, all you need to do to change the location of your WP site, even if you’re using a new URL.

Kerry is a prolific technology writer, covering a range of subjects from design & development, SEO & social, to corporate tech & gadgets. Co-author of SitePoint’s Jump Start HTML5, Kerry also heads up digital content agency markITwrite and is an all-round geek.

Get your free chapter of Level Up Your Web Apps with Go

Get a free chapter of Level Up Your Web Apps with Go, plus updates and exclusive offers from SitePoint.


  • Michael Houghton

    “Preferably not” is not strong enough. You need to stress *not*.

    You can’t use a search and replace tool and expect your site to continue working unless you are lucky enough to be replacing one URL part with another URL part of exactly the same length.

  • Matt
  • Dave

    Duplicator and BackupBuddy…
    Much simpler! Takes me 10 to 15 minutes to move a site and most of that is waiting for the zip file to upload.

  • marie

    Hi! I’ve followed all the steps and get the install wordpress screen! Any idea what I could have done wrong? Help!

    • Vernon S. Howard

      @Marie Check your wp-config.php file db connection info.

  • Jeremy

    I use BackUpBuddy for deploying sites from dev to production and also for moving sites. Works perfectly every time! Well worth the investment. And its currently 35% off thru the end of the month!

    http://ithemes.com/purchase/backupbuddy/

  • Matt

    Tried Backup Buddy. Hated it. To each their own.

    • Jeremy

      Any particular reason?

  • Dave

    If you have SSH access you can ssh into the current server and make your wordpress folder into a gzipped tarball. Then FTP this to the new server, SSH into your new server and untar/zip it. You’ll still need to modify the wp-config file and database as necessary, but uploading a zip file and then unzipping it will generally be faster than uploading lots of individual files.

  • Jay

    I’ve used the free Duplicator plugin. It has proved (to me) to be the simplest way of cloning a site from one host to another, or from a development environment to a live server. Did I mention that it is free…?

    • Robert Lilly

      +1 for Duplicator. It’s fantastic, unless you have a Multisite installation.

  • Sergio

    From my experience, is as easy as: 1) make a dump of the database using a plugin such as WPMigrateDB; 2) copy de files; 3) restore the database. That’s it. But sometimes additional plugins make things a bit difficult (encoding paths inside databases, etc, etc).

  • Bert

    Thank you for the write up but maybe I am missing something. The process I use (similar to Sergio) seems a bit easier – especially if renaming the site. I just dump the database to a SQL file, open the SQL file in a text editor and find/replace all instances of http://url1.com with http://url2.com. That takes about 2 seconds.

    After I have copied all the plugins, themes, uploads directory, files and etc. from the old location to the new location, I import the modified SQL.

    The only issue with this is that “sometimes” if there was a “Text” widget in a sidebar, for instance, that text doesn’t get copied. (I haven’t figured out why yet).

  • Sam Dreadthug

    This is lot easier. I have migrated wpcares.com from bluehost to hostmonster

Related books & courses
Introduction to Wordpress

Available on SitePoint Premium. Check it out now!