Migrating WordPress website to a new hosting provider is not a difficult task and only takes 20-30 minutes if your database is not big. I have recently migrated one of my WordPress website from godaddy.com to arvixe.com keeping the domain name same and so writing this post.
- Put your website in maintenance mode
If your website has a significant traffic that continuously updates your database then you should place your site in off line mode to make a consistent database backup. Log in to your wp-admin section of WordPress and install the required plugin. There are some plugins: i) http://wordpress.org/plugins/maintenance/ ii) http://wordpress.org/plugins/wp-maintenance-mode/ by which you can place your website in offline mode. But site with less traffic or for new WordPress site you can ignore this step.
- Turn off Permalinks
If your Permalink is set other than default , set it to default. In My case it was Post Name. Log in to your wp-admin area. Go to Settings -> Permalinks and set permalinks to default.
- Deactivate all installed Plugins except Maintenance Plugin
It is recommended to deactivate to all of your plugins. But I think only deactivation of caching plugins like “WP Super Cache” and “W3 Total Cache” is enough. Go to Plugins and deactivate plugins.
Don’t deactivate Maintenance Plugin if you have installed any to place the site in Maintenance mode.
- Download WordPress files
Backup your WordPress files using your favorite FTP clients and then upload those to your new hosting domain location. You can use Filezilla. Download it from https://filezilla-project.org/download.php
Create a wp-files folder on your desktop and download all WordPress files from your existing hosting directory.
- Import your Database Backup to your new hosting Database
Now you need to import the backup Database into your new hosting WordPress Database. Create a Database in your new hosting location. Go to cPanel Database portion and click MySQL Database
Go to “Create New Database” section and create a new Database
Go to “Add New User section” and create a new Database user
Go to “Add User To Database” section and give permission the user to access the Database
Now, go to your new hosting PhpMyAdmin. Select the newly created Database and import the backup Database file to it. If your backup Database file is big , zip it and then import.
- Configuring WordPress after migration
After uploading all WordPress files to new location, you need to modify wp-config.php file. You can do it by your cPanel File Manager or directly from your FTP client View/Edit option
You need to modify the following lines
define('DB_NAME', 'new database name'); /** MySQL database username */ define('DB_USER', 'new database user'); /** MySQL database password */ define('DB_PASSWORD', 'new database password'); /** MySQL hostname */ define('DB_HOST', 'localhost');
- Testing your WordPress website after migration by hosts file modification tricks
At this point, you have done the work to migrate your website to new Hosting. The last step before taking the website live on new servers is to test your website. To do this, you will need to modify your hosts file on your computer.
Actually , when you browse your website like www.example.com , you computer must first figure out which web server to contact to retrieve the webpage. It will find this information out by asking a DNS query to your nameserver. All the nameservers still know your website is located on your old hosting. But if you modify your hosts file , then your computer will not look up DNS to find out your website hosting location. These are the steps to modify hosts file
- First ping your website from command prompt
You will see an IP of your old hosting webserver is returned. My website www.techinfobest.com was located on GoDaddy.com and my webserver IP was 184.108.40.206.
ping www.techinfobest.com Pinging techinfobest.com [220.127.116.11] with 32 bytes of data: Reply from 18.104.22.168: bytes=32 time=275ms TTL=46
- Run Notepad as administrator
If you were running Windows XP or lower, you won’t need to run it as administrator as this functionality only exists in Vista and above. Locate Notepad within your Start menu. If it is not already there, you can type “notepad” into the search box to show it. Then, right-click on it and click on “Run as administrator”.
- Opening your hosts file
After you have Notepad up and running as administrator, you can then locate your hosts files and open it. While not all Windows versions store it in the same place, it is typically located within
Now, we need to open our hosts file. With Notepad already open, click on “File”, then “Open…”. If you are using Windows 8, Windows Defender is running by default and it prevents the change of the HOSTS file. You will need to allow this file to be edited by going into Windows Defender and doing the following steps:
- Navigate to Windows Defender hover over the right corner to bring up the navigation bar. Click on the icon that appears to be a magnifying glass to start a search. Type in “Windows Defender”, click on the icon that appears. It will be labelled “Windows Defender.” Click on this icon and the application will launch.
- When Windows Defender opens, click on the tab labelled Settings.
- Next, type in the location of the hosts file based on location of the Windows installation. Here’s the default path: c:\windows\system32\drivers\etc\hosts
- Click on the Add button and you’ll see it added to the list beneath the file locations.
- Click on Save Changes in the bottom right and then close Windows Defender.
- The next step will be actually edit the file. As per the instructions above, you will need to edit the file as an Administrator. Hover over the right side again, and then search for “Notepad”. Open it as an administrator.
- Open the file as per your HOSTS file path.
- Make your edits, and click on SAVE by clicking on “File” to bring up the menu. This completes the HOSTS file edit in Windows 8.
- Modifying your hosts file
Now that you have your hosts file open, its time to edit it. Within your hosts file, you should see something like the following:
# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 22.214.171.124 rhino.acme.com # source server # 126.96.36.199 x.acme.com # x client host # localhost name resolution is handled within DNS itself. 127.0.0.1 localhost # ::1 localhost
Now, you need to add your new hosting webserver IP address at the bottom of the file. In general, you will find your new webserver IP addresses on the left side of your new cPannel under name of Shared IP Address or Dedicated IP Address. I shifted to arvixe and found the IP address on the left named Dedicated IP Address.
However, on GoDaddy cPanel I found the hosting address under name Website(s) IP Address
After adding new webserver IP address to hosts file, it would like
# localhost name resolution is handled within DNS itself. 127.0.0.1 localhost # ::1 localhost 188.8.131.52 www.techinfobest.com 184.108.40.206 techinfobest.com
- Flushing your DNS cache
If your computer has cached your DNS, you will need to clear it. Open you command prompt ( as Administrator if you use Windows > Windows XP) and type the following command
- Check hosts file modification works
Go to command prompt and ping again your website domain address. I pinged www.techinfobest.com and got return new hosting IP address
C:\>ping www.techinfobest.com Pinging www.techinfobest.com [220.127.116.11] with 32 bytes of data: Reply from 18.104.22.168: bytes=32 time=287ms TTL=110 Reply from 22.214.171.124: bytes=32 time=280ms TTL=110
- Browse your website and log in to your wp-admin area
Clear your Browser cache then close and open it again. Browse the website. In my case, I browsed www.techinfobest.com. At this stage only you are browsing your website hosted on your new hosting location where as all others are still browsing your website hosted on old hosting provider.** If you browse from Linux or Unix based operating system , the above procedure is very easy. Just add entry in /etc/hosts file. Then your server will not go for DNS query rather use /etc/hosts file entry.
- Replace your old domain name by new domain name
This step is required only if you change your domain name also. It my case I didn’t require this. There is a nice free PHP script is available on https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
or you can do it manually by yourself
- Replace your WordPress (URL) Address and Site Address (URL)
In “Settings” → “General,” change both WordPress (URL) Address and Site Address (URL). Like your existing domain is www.example.com
and new domain is www.examplenew.com. So, after modification WordPress (URL) Address and Site Address (URL) would be
- Correcting image and post links
Log into your cPanel interface and go to PhpMyAdmin. Select your WordPress Database and open an SQL window. Run the following command
UPDATE wp_posts SET post_content=(REPLACE (post_content, '',''));
Be sure to replace with the old sitename and with the new site name. For instance, our original site was example.com and the new test site will be at examplenew.com so the code should appear as below:
UPDATE wp_posts SET post_content=(REPLACE (post_content, 'example.com','examplenew.com'));
Click on the Go button to run the code and change the URLs for all images and posts of wp-posts table.
- Replace your WordPress (URL) Address and Site Address (URL)
- Back the Permalinks to your desired format
- Reactivate all required plugins and deactivate Maintenance plugin
- Delete your hosts file entries
If everything seems ok, you can delete or comment your newly added entries to hosts file.
- First ping your website from command prompt
- Modify your DNS record
At this stage , you need to modify your DNS record on your Domain Name registration provider. My Domain Name was registered on GoDaddy.com. So I went their Domain Management Section and replace my DNS record with my new hosting (Arvixe) nameservers. Arvixe’s nameservers were NS1.SQUIRREL.ARVIXE.COM and NS2.SQUIRREL.ARVIXE.COM
It may take some hours to update your new hosting location to all nameservers of the world.
The above procedure may seem little lengthy but this is the safest way of “Migrating WordPress website to a new hosting provider”. All the stages may be not required like “Place website in Maintenance mode”. Even you can ignore hostfile modification tricks if you confident that don’t need to test on the new server . However, you have to follow steps like Plugin reactivation, Back the Permalinks settings, Domain Name replace( if required). Migrating WordPress website from your local machine to new hosting provider is also almost same procedure.