Migrating a website from cPanel shared hosting to VPS like Linode

Migrating a website from cPanel shared hosting to VPS like Linode

Shared hosting has provided affordable hosting to millions of websites around the world. It’s easy to setup and affordable thanks to self-service web hosting interfaces such as cPanel, ISPConfig, Vestacp etc.

Why you should leave shared hosting

However, shared hosting has got some of its short comings. For instance, you don’t have root access to the server hosting your application which means you are limited in what you can do. You can’t install custom packages or apply certain configurations. Also there’s a resource limit when you go shared hosting. Each website is given specific bandwidth usage and disk usage which you can’t go beyond.

This is where you might opt for something that has more flexibility. Renting a Virtual Private Server or VPS has become very cheap these days thanks to rise in cloud computing. You can get a good VPS for as low as $5/month for around 512MB to 1GB of RAM depending on the vendor. My favorite is Digital Ocean and Linode.

Why you should stick with shared hosting

While VPS have become cheap, be reminded that you are totally in charge of your house; server setup, configuration, security, maintenance, performance tweaks, upgrades, network configuration, DNS setup etc. If this is too much for you, I suggest you stick with shared hosting unless you can get someone with advanced Linux System administration to do stuff for you.

How can do you painlessly migrate a huge website from cPanel host to your private server?

Hosting panel vs Command line administration

I assume you already have setup your VPS and you all set. Everything will be done via the command line although you can opt for paid or Free Hosting managers. You can setup your Setup cPanel on your box — I understand the irony — or something more striped down like Sentora or VestaCP which I prefer or you can experiment with a whole host of alternatives.

But for starters, I really recommend that you get a bit dirty with the command line because one way or another, you will have to at one point use it. You can take a quick tutorial on Linux/Unix commandline with Michael Hartl’s Learn Enough Command Line to Be Dangerous.

Moving website Files and folders

cPanel has a great web-based file manager that developers use to upload, edit and delete their website files. It’s great. Before moving, I suggest you compress files in public_html folder which is the directory root of your website.

To compress files, go to file manager > select public_html > right click > select compress. Pop-up menu will come. Select compression type. I prefer Tar Archive. Enter filename of compressed archive and click compress. Let’s say you called it migrated-site.tar.gz

After the compressing is done, you can now move files over the cloud to your new VPS without downloading them first to your local machine.

To do this, we use ftp since this is what your hosting provider gives you. We shall actually use Linux’s wget download utility which can be used to download files from an FTP server. Of course you can also use the ftp command line client to do the same, but why not use a one-liner.

So SSH into your VPS, and cd to whatever directory you want to store your website files and issue the following command (edit parameters to suit your case).

wget -m --user="ftp-username" --password="ftp-password" ftp://your-domain.com/migrated-site.tar.gz

Depending on the size of your website files, the download usually happens within seconds or minutes.

Now you can uncompress the files with the tar utility for tar archives.

tar -xzvf migrated-site.tar.gz .

With the website files moved in an instant, it’s time to migrate your website database. I’ll assume you are using Mysql db.

Migrating the website database

Migrating the website database is also fairly easy. Usually databases are small — usually a few MBs so you could use cPanel’s PhpMyAdmin interface, and then export and boom, the .sql file is downloaded to your local machine. But then you have to re-upload this backup file to cloud VPS using either scp, or rsync or ftp, but this could be time consuming and bandwidth intensive if you are dealing with a big sql dump and you have slow internet connection.

The method I propose is to directly move your website database from cPanel host to your VPS.

cPanel has this “Remote Mysql” feature which enables you to add a specific domain or hostname name or IP which is allowed to remotely connect to your MySQL databases. Really awesome.

Under database section, select Remote Mysql, enter the public IP of your VPS under “Add access host”. That’s it.

Now move over to your VPS and remotely dump database file of your website like so;

mysqldump -u [username] -p[db-password] -h remote.site.com DBNAME > migrated-site-db.sql

Replace DBNAME with the name of the database you’d like to download to your VPS. Within seconds, depending on the size your website database, the db dump will be done.

Now you can restore the website db assuming you already have Mysql installed, database and website user created on Mysql with the Mysql command like so;

mysql -u [username] -p[db-password] DBNAME

That was really snappy. Nothing was downloaded your local machine and re-uploaded to the new VPS. It happens in the cloud and it could take a few minutes before your website starts running on your new shiny VPS.


Leave a Reply