Skip to main content
  1. Tutorials/

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

Tutorials Apache Getting Started Ubuntu WordPress
Status: Deprecated>

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:

Upgrade to Ubuntu 14.04.
Upgrade from Ubuntu 14.04 to Ubuntu 16.04
Migrate the server data to a supported version

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>

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>

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)>

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.

Back Up the Database>

Back Up the Database #

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

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

Step 2. Set Up the Cloud Server with LAMP Stack>

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>

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>

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>

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>

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>

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>

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>

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>

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