Moving WordPress from one host to another might look like a huge task and you might be afraid of losing data or corrupting your database. Believe me, moving WordPress from one host to another is a very simple task, and takes very little time. We have been doing more complicated tasks like changing WordPress domain and moving then moving the sites in less than 20 minutes. The trick is to know what to do and the order in which you have to do.
This guide will help you move your WordPress powered site from one host to another with zero to a very minimal down time.
Inform everyone about the move
If you have a multi author blog, or if you have lot of people working for you to generate content, give them a holiday. Ask them not to post or update anything until further notice. This is because, if they update or add a new post after we take the database backup, then will loose the changes they made ad they will be doing it on the old host.
If your blog gets a lot of comments, you might loose some newly added comments, to keep them to minimum, we will move the database after everything is done in the last step.
Upload WordPress on new host
You could just copy over all your files from old host to new host but along with it comes any malicious code injected into your WordPress files. I always upload a fresh copy of WordPress.
Get a fresh copy of WordPress from WordPress.Org and upload the files in the same directory path they were on your old host.
If WordPress was installed in your root folder i.e, public_html on your old host then upload it to the root folder. If it was installed in a subdirectory say blog, at public_html/blog then create the blog directory and upload your WordPress there.
Create Database for WordPress on new host
I’m assuming you are on cPanel based hosting. Even if you are on a different host, the idea is similar.
- Login to your cpanel on new host, and goto MySql Database Wizard.
- Enter the database name, doesn’t have to be the same as on your old host. Can be anything.
- Next screen asks you for db user name, can be anything. Choose a strong password, and note it down
- On the next screen, check all privileges box and click next step and you are done. Note down database name, username, and password on this screen to a safe place, we will need it in further step.
Copy files from old host to the new host
There are three ways in which you can copy the files from your old host to new host. Before we see how o move files, lets see which files we should be moving. Ideally, we have to copy the whole wp-content folder. But if you are moving to a new host because your site has been compromised or if you have even any slightest doubt that your site might have been compromised then you should not copy the whole wp-content folder. This folder includes themes and plugins folder which contain php files and may be injected by malicious code. Instead, just copy the wp-content/uploads directory and make a list of themes and plugins you are using and when the move is complete install them one by one.
How to copy files from old host to new host
- Login to your cPanel file manager, and navigate to wp-content folder.
- Compress the folder and download it.
Now upload the above zipped file to wp-content folder on your new host and unzip it.
Note: If your site has been hacked before, unzip the archive to your desktop and go through the folders to make sure there are not malicious files.
FTP into your old host, and download the uploads folder to your desktop, and then upload it back to the new host. If you have a large site, this method is not recommended as it will take a lot of time to download files and sometime the connection may timeout.
You can use the SCP command to copy files from your old host to new host over the wire.
Install the theme and plugins
Upload the the theme and plugins via cpanel or FTP. We can do this via wp-dasboard to, but then we don’t have a chance to verify if everything is working as expected before making the changes live.
Create the wp-config.php file
- Goto the root of your wordpress installation on new host and rename wp-config-sample.php to wp-config.php
- Now edit the file and update the database name, database user and password with the ones you created in the first step. Database host is usually localhost.
Copy the database to new host
- Login to cPanel on your old host and open phpmyadmin.
- Navigate to the database of the WordPress site you are moving (If you are not sure about the name, you can check the wp-config.php file). Then click on export.
- Select custom export method and select all tables. If you have a popular site with lot of posts and comments then your database can be large. In that case you can export tables one by one or in groups. TIP: Emptying spam and deleting post revisions can reduce db weight considerably.
- If your site has been hacked, then unzip the database and search for base64_encode, eval and remove them. If they injected pharma, casino and other malicious links, search for parts of those links and if you are lucky, the hacker ( I would like to call them D**** head ) might have not obscured the links and you should be able to find them with simple search.
- Now login to the cPanel on your new host and open phpMyAdmin and select the database you creates in the very first step. Now click on import and upload the cleaned zipped file we downloaded above.
Verify everything is working as expected
If you are a brave soldier and confident that you did everything correctly you can skip this step.
Edit the hosts file on your computer to point your site to the new host. Here is an article on how to edit hosts file on OSX, Windows 7/8 and other linux operating systems
What this does is, show you the site on new host while the rest of the world sees the old site.
Check your site to make sure everything is working as expected.
Take these changes live
Once you are sure that everything is working as expected, goto your domain control panel and update the namervers or ip of your new site. With in a day or two, DNS propagation will be complete and you have successfully cleaned and moved your site to a new host.
Though this tutorial is lengthy, moving WordPress sites is a simple task and we could do it in less than an hour for an average site. If you would like to have the experts handle the things for you. We are available for hire.
[button link=”http://swiftthemes.com/wordpress-services/#quote” size=”large” style=”thumbs-o-up” color=”primary”]Hire Satish Gandham[/button]