Back to blog

When working with your WordPress website, it is not uncommon if you need to move WordPress around within your server, or even relocate it from one server to another. Don’t worry – you won’t have to go through the installation process over again.

Changing Your Website's Hosting

The fact is, WordPress is a flexible CMS, capable of taking care of such situations. Hence, there is quite a simple way to transfer WordPress from one hosting to another – and with our guidance, you’ll master this process in no time.

When Your URLs and Domain Name Stay the Same

It will hardly take you any effort to move your domain without changing Site and Home URLs of your WordPress, as in the majority of cases it is done by simply moving the files.

  • In case the URL and database remain without changes, all you have to do to move WordPress is copy your files and the database.
  • If the database user or name changes, specify the correct values in the wp-config.php file.
  • To test before you switch, you are to access the database table “wp_options” through phpMyAdmin or a similar tool, and temporarily change “home” and “siteurl” there.
  • In case you had any type of rewrites (or permalinks) setup, you should reconfigure these permalinks and disable .htaccess when it goes live.

If you are keeping the domain, yet change to a new server, to get everything going you simply have to update the database/user data in the wp-config.php file and upload all the other files as they are to your new server.

When Your URLs or Domain Name Are Altered

If it happens so that your URLs or domain name change – for instance, from http://example.com to http://example.com/site, or http://example.net to http://example.com, there are several more things to be concerned about. Although the database and the files can easily be moved, it is the references to old location or the domain name that can trigger some problems with theme or links display, as they still remain in the database.

In case to change the URLs you do a search and replace on your whole database, it is likely that issues with data serialization will appear. This happens as a result of some widgets and themes storing values with the length of your URL marked, so whenever this changes, things may go wrong. However, there are two ways of preventing this serialization problem:

  1.  Just go through a search and replace procedure on the wp_posts table.
  2. Change all instances with the Search and Replace for WordPress Databases Script (this option is preferable for developers, as it is really time-saving, as opposed to the 15-step procedure described below).
  3. If you don’t want to get involved with uploading the scripts to your server, you are free to use an online tool Online WordPress Serialized PHP Search and Replace, which makes it possible to replace an old URL or domain with a new one, and fix the serialized data in the meantime.
On The Same Server

Moving your WordPress files from one place on your server to another (which means changing the URL) can be a tricky job that requires extra attention.

The following is a step-by-step instruction that will help you transfer your WordPress website to a new location on the existing server:

  1. Choose one of these two options to create a new location for your site: In case you decided to move your WordPress core files to a new directory, you should create this directory first. Otherwise, if you wish to relocate WordPress to your root directory, it is important that you ensure that all your files (such as .htaccess, index.php ext), which will be copied are either moved, or have backups. Also, make sure that the root directory is prepared for the new WordPress files.
  2. Log in to your website.
  3. Navigate to Administration > Settings > General panel.
  4. Find the box for WordPress address (URI): in this box, update the address to the new location of your principal WordPress core files.
  5. Find the box for Site address (URL): in this box, update the address to the new location, which must correspond to the WordPress (i.e. your public website) address (URI).
  6. Hit “Save Changes”.
  7. Please note that you absolutely should not attempt to open or view your site at this point!
  8. Relocate your WordPress core files to a new place, including the files located within the original directory (http://example.com/wordpress), as well as each sub-directory.
  9. Now you can try and open your website by navigating to yourdomain.com/wp-admin. Please consider that it may be necessary for you to go to yourdomain.com/wp-login.php.
  10. In case you are using permalinks on your website, it is essential that you move to Administration > Settings > Permalinks panel in order to update your permalink structure to match your .htaccess file. This file should be placed in the exact same directory, as your main index.php file.
  11. Also, while transferring WordPress, you should update the existing image/media links to uploaded media with the new location. Otherwise, they will refer to the old folder, which may cause problems. This can be done manually in your SQL database, with the help of a search and replace tool, or through Velvet Blues Update URLs plugin.
  12. Depending on your ISP, it is possible that your permissions get changed. In case you notice any files with “0000” permissions, you should change those back to “0644”.
  13. If your current WordPress theme supports menus, it is best you check the links to your home page, as it is likely they still the old sub-directory embedded in them. To update them, navigate to Appearance > Menus.
  14. In order to avoid server error, it may be necessary to restart your server (this is more common with MAMP software (Mac)).

Note: URI locations should be set BEFORE you actually move the files.

What to Do If You Forgot to Change the Locations

If for some reason you moved the files before you changed the URIs, no need to panic – there are two ways you can fix that:

  1.  Suppose you transferred your files that were originally located at /path/to/old/ to a new place at  /path/to/new before you managed to change the URIs. To amend that, you need to make /path/to/old/ a symlink (Windows uses the name “shortcut”, which is equivalent to“symlink”) to /path/to/new/, for instance ln -s /path/to/new /path/to/old. Afterwards, you can go back to the abovementioned steps as normal. When done, the symlink can be deleted (although you are free to keep it if you want).
  2. In case you forget to change your Blog Address and WordPress Address, it will be impossible to change it via WordPress interface. Still, this problem can be taken care of if you have access to the database. Hence, go to your site’s database and find the wp_options table, which stores every option that can be set in the interface. Your Blog Address and WordPress Address are stored as home and siteurl (the option_name field). Simply change the option_value field to the correct URL for the records with option_name=’siteurl‘ or option_name=’home‘, and the issue will be fixed.
What to Do If You Have Changed Your WordPress Site Url By Mistake

Let’s presume you unwittingly changed your URIs and cannot move the files to the new location (yet you still have access to the login page, either through redirection, or any other way).

Use wp-login.php to set (or reset) the URIs. Search for the following line:

require( dirname(__FILE__) . ‘/wp-load.php’ );

then paste the following strings beneath:

//FIXME: do comment/remove these hack lines. (once the database is updated)

update_option(‘siteurl’, ‘http://your.domain.name/the/path’ );
update_option(‘home’, ‘http://your.domain.name/the/path’ );

Done and done! You can test your website now, to ensure that it works without any errors. In case your changes required modifying the address, don’t forget to inform your users about the new address. Likewise, it is necessary that you add redirection instructions in your .htaccess file, so that your visitors will find their way to the new location.

How to Transfer to a New Server

If you decide to relocate WordPress from one server to another, it is best that you begin with making a backup for your data. This way, your WordPress database, along with all core files, plugins, images and other files on your website will be safe in case something goes wrong.

Please note, if you choose to change to a new server, yet you want to keep the same domain, all you have to do is update your database/user information in wp-config.php file, and then upload everything to a new server without any further changes.

If You Are Not Concerned About Your Old Site’s Work
  1. Copy your main WordPress files from the OLD site to your hard drive, and edit wp-config.php to be appropriate for the new server.
  2. Return to your OLD site and navigate to Administration > Settings > General, where you have to change both URLs to those of your new website.
  3. Log in to your server, move to phpmyadmin to export and save your database as a file (it is still recommended that you keep the old one, just to be safe). Once finished, upload the copy of your WordPress core files (with modified wp-config.php file) together with the new database to your new server. There you go – all done!
If You Want Your Old Site to Stay Functional

Warning: Before you proceed, you should ensure that your old website’s WordPress database is backed up!

Step 1. Activate Your New Site
  1. Download all of your WordPress installation files to your hard drive. Make sure you folder name indicates that these are your OLD website’s installation files.
  2. Download your database.
  3. Return to your OLD website. In the options, enter both of your new site’s URLs.
  4. Download all of your WordPress installation files to your hard drive once again. This time, name the folder so that it will be clear to you that it contains your NEW website’s installation files.
  5. While keeping the previous one, download the database again. When finished, upload this newer database to the new server. We suggest you to use the same name for your databases, as it will be a lot easier for you this way. Likewise, it is best that you use login credentials you had on the old server while creating a user on the new server.
  6. In case you decided to use a different user and/or database name (see previous step for more information), you have to accordingly edit wp-config.php that can be found in the folder with your NEW site’s installation files.
  7. Ultimately, upload the folder with your NEW website’s installation files to your new site. Voila – at this point, your new site should be working just fine! 
Step 2. Restore Your Old Site
  1. Delete the your OLD website’s database on the original server (hopefully, you followed our advice and made a backup copy on your local computer before making any changes).
  2. Also, while on the original server, upload your OLD website’s folder with installation files, choosing to overwrite the existing files. Also, if you prefer more cardinal way, you can just delete the installation folder on your server and then reupload the files from your OLD website.
  3. Finish by uploading your OLD website’s database to the server from your local computer. That is about it!

To make copies of comments, categories, posts, pages and custom fields (such as data, ping status, permalinks, post status etc.), follow these instructions:

  1. First, install a new WordPress website.
  2. Log in to your old site and move to the Admin Panel. Then, navigate to Manage > Export and choose “all” in the menu Restrict Author.
  3. Hit the Download Export File button.
  4. On your new website, move to Manage > Import page to choose WordPress item.
  5. Next, a pop-up page will appear. Select the file you have just exported, and click Upload file and import.
  6. You will be redirected to Assign Authors page, on which you are to assign posts to an existing user or create a new user.
  7. Hit “Submit”.
  8. Once finished, click “Have fun”. 

FYI: in case you have default articles on your new website (such as info page, or hello world), they will not be deleted, as while using this method they are only added. However, if you choose the previous procedure, the articles will be erased on your new site.

How to Transfer WordPress Multisite

Moving multisite is a more complicated job, due to the fact that the database has several folder locations, as well as multiple references to the server name. If you are keeping the domain name and just transferring your site to a different server, you will hardly have to rack your brains, as you can simply copy the database and all files over. This process is identical to the traditional installation.

However, changing domains requires extra effort. This way, you can move Multisite most easily by relocating the files, editing the wp-config.php and .htaccess files (if the folder containing Multisite was renamed), and manually editing the database. Also, you should search for every instance of your domain name, and update it accordingly. Unfortunately, making this step automatic is not that simple. We suggest you don’t try blanket search/replace without the Search and Replace for WordPress Databases script. Searching/replacing either one of the wp_x_posts tables is completely safe, though.

If you need to relocate Multisite from one folder to the other, it is essential that you modify the wp_blogs entries, so that the folder name will be changed correctly. Still, we recommend you to review both wp_blogs and wp_site manually in any case, just to make sure that all of your sites were changed without errors.

Furthermore, you should manually go through all the wp_x_options tables to search for ‘three fields. Once found, edit them as needed:

  • home
  • siteurl
  • fileupload_url

Ultimately, whenever you are moving from subfolders to subdomains, or contrariwise, don’t forget to update the value for SUBDOMAIN_INSTALL and the .htaccess file in your wp-config.file appropriately.

Hence, although transferring your website to another server can seem like a lot of work, our tips will guide you through the process, and you will find that it is a lot easier than you initially thought!



Popular Posts

Like This Article? Subscribe to Our Monthly Newsletter!

Comments are closed.