Tutorial

How To Migrate WordPress from Shared Hosting to a Cloud Server with Zero Downtime

Published on June 26, 2013
author

Ramesh Jha

How To Migrate WordPress from Shared Hosting to a Cloud Server with Zero Downtime

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

Moving to a Cloud Server

Many bloggers start with shared hosting. This may be good for starting out, but when traffic grows (e.g. above a few hundred visitors per day), you should consider moving the blog to a personal cloud server. Moving to one isn't very complicated, just follow the steps correctly and you can migrate a WordPress blog/website within a few hours, without any downtime.

Step 1. Create a Backup

You need to backup all your files, along with the MySQL database (from your current shared hosting server). Most of the shared hosting providers have a simple GUI for managing servers, such as cPanel.

Backup Files (images, themes, plugins)

You don't need to backup core WordPress files, but you must backup images (you may have already uploaded for a post), themes, and plugins. In order to do this, first, create an archive of the wp-contents directory (right-click => compress as zip), then download it.

compress cpanel dir

Back Up the Database

In cPanel, go to "Backup Wizard => MySQL Databases".

wizard

You'll be able to download the MySQL database in *.sql.gz format. Save it as backup_db.sql.gz on your desktop. backup mysql db

Step 2. Set Up the Cloud Server with LAMP Stack

Launch a droplet (cloud server) with Ubuntu 12.04 and follow this guide for the basic setup process: Ubuntu Server Setup. Now that the cloud server is set up, you need to install the WordPress dependencies such as MySQL, PHP and a web server like Apache. Follow this guide to set up a LAMP stack.

Step 3. Install WordPress

Once the LAMP stack is set up, install the latest version of WordPress. To do so, simply follow this guide: Installing Wordpress on Ubuntu.

Step 4. Create a Virtual Host

Create an Apache virtual host for handling your Wordpress blog. Create a new file in the site-available directory:

sudo nano /etc/apache2/sites-available/yourdomain.com

Add a virtual host (replace yourdomain.com and username accordingly) for the blog. Each VirtualHost block defines a seperate cloud server and the number 80 indicates the port that Apache will listen on. ServerName represents your domain name and DocumentRoot should point to the root of the WordPress directory.

<VirtualHost *:80>
     ServerName yourdomain.com
     DocumentRoot /var/www/
</VirtualHost>
<VirtualHost *:80>
     ServerName www.yourdomain.com
     Redirect permanent / http://yourdomain.com/
</VirtualHost>

Then enable this virtual host using the Apache utility a2ensite. It takes the above configuration and tells Apache to listen for yourdomain.com.

sudo a2ensite yourdomain.com

Now reload the Apache server. Whenever you make any changes in server configuration, you must reload the server to apply those changes.

sudo service apache2 reload

Step 5. Restore Database and Files

The WordPress installation is now set up but you haven't imported your old articles, images, themes, etc. Let's upload the files first.

Upload the Backup Files - MySQL Database and File Contents to VPS

scp is very handy for uploading files. Like FTP, you can transfer files, but SCP does it securely over SSH. For uploading files, you need to pass two arguments to the command. The first one is the location of the file you want to upload and the second one is the target server (in the form of username@server_ip_address). To upload the backup files, simply execute these commands locally (on your computer) and it will upload the files to home directory of the server.

scp ~/Downloads/backup_db.sql.gz username@server_ip_address:
scp ~/Downloads/wp-content.zip username@server_ip_address:

Restore the Database

To restore the database, login to the server and type (replace database_name, database_user accordingly) the command below:

mysql -h localhost -u database_user -p database_name < backup_db.sql.gz 

The command requires a few arguments: the -h option for specifying the host address (in this case it's localhost, because the database is running on the same server), the second argument, -u, provides the database username, the third option, -p, means the password will be supplied on prompt, the fourth option specifies the name of the WordPress database, and the last argument is the input - the backup database.

You will be asked to enter the password for the database user. Within a few seconds, the database contents will be imported to the specified database.

Restore wp-content Files

To restore themes, uploaded media (images, videos, etc.), and plugins, simply extract (using the unzip command) the zip archive. It will extract and merge the contents into the existing wp-contents directory.

sudo unzip wp-content.zip -d /var/www/

Step 6. Test your Blog

To achieve zero downtime, this step is important. You have to make sure that the blog is set up properly on the new location. To do this, first update your hosts file.

sudo nano /etc/hosts

Add this line to the hosts file (now when you visit yourdomain.com, it will point to your new server, but only on your computer - this makes testing easier).

server_ip_address  yourdomain.com 

Next, clear your DNS cache (since you've updated the hosts file, you must clear the DNS cache to apply the changes. nscd is nice little tool for flushing out the DNS cache results)

sudo service nscd restart

Now, if you visit yourdomain.com, it will be loading pages from your new server. If it looks as expected (all your articles, images, pages, plugins, custom designs etc.), then it means you are all set and you should move on to the next step. Otherwise, try to figure out what went wrong. (After testing successfully, remove the above line from the hosts file).

Step 7. Update Your DNS Settings

Now you should update the DNS settings with your Domain Registrar. For the A record, update the IP address to the new value (IP address of your VPS) or you could also move your DNS to your VPS provider (and add A records there). For DigitalOcean, you need to put these name servers:

ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com

Note: Your DNS server will start propagating the new values but it will take some time, so do not terminate your old shared hosting immediately after the transition (preferably after a day).

Article Submitted by: Ramesh Jha

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Ramesh Jha

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

<VirtualHost *:80> ServerName example.com … Redirect permanent / http://yourdomain.com/ </VirtualHost>

Maybe example.com must be yourdomain.com ?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
June 30, 2013

@seobag Replace yourdomain.com and example.com with your domain name.

Yes, I understood it, but yourdomain.com and example.com in this tutorial looks like it was two different names and I think that must be correct to change example.com on yourdomain.com in this example.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 1, 2013

@seobag: Updated the article - thanks!

How do I install multiple wordpress sites on a droplet?

Hi, I’m using mac. How to upload the database file from my computer to the server? How to locate the file source on my mac? I put the file on the desktop. I’ve also change the port number

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 15, 2013

@marbolec Take a look at the “Upload the Backup Files - MySQL Database and File Contents to VPS” section.

Replace ~/Downloads with ~/User and append “-P 1234” to the command (where 1234 is your new ssh port).

wow well amazing site digital ocean XD

i want to start my first account here for learn more about linux servers

excellent price for 5 dollars i can test my skills in linux servers and learn XD

Sorry Kamal, I meant how to I set up multiple single installs using virtual hosts. The installing wordpress tutorial installs wordpress at the root, what if you are running multiple domains with multiple single wordpress installs?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.