Recommended VPS Complete list of best VPS hosting providers.

How To Move Website From cPanel-based Hosting To Your Server

This guide will show you how to move or migrate a website from cPanel to the unmanaged server you’ve setup. The word “Server” here refers to either VPS or Dedicated server. The main purpose of this blog is to teach newbies how to manage unmanaged server so if you feel you are a server ninja, you can simply skip this page or you may also add your opinion and tip us.

I posted some basic tutorials on how to build and setup your own unmanaged server either running Apache or Nginx web server. Well, but for Ubuntu (or Debian) server only for meanwhile but I promise you to write some other tutorials for other most common Linux distros. So, lets get it on..

Preparation Before Site Migration

  1. Make sure you have access to your old web host. I assume you have the username and password to login to your site’s cPanel. You can access it via either http://example.com/cpanel or http://example.com:2082/ or may also use your site’s IP address like http://000.000.000.000/cpanel or http://000.000.000.000:2082/. I will call your old web host with cPanel in it as “old host” and its IP address as “old host ip“.
  2. I also assume you have built and setup your own server and it is ready to host a website (it should already has a working web server, mail server, php5 and MySQL server). I will call your new server as “new server” which is the destination of where you wish to migrate your website to. I will also call its IP address as “new server ip“.
  3. In this guide I will use my playground server running Ubuntu OS. If you want to setup the same server you can simply read my previous post how to setup LAMP and LNMP or LEMP.
  4. I assume you have proper knowledge to access your new server via SSH. In Windows, you can simply use Putty. Read my previous post about how to use Putty to SSH-ing your server.
  5. This guide can be applicable to (I think) all kind of website with MySQL database. In this guide I will try to move a blog running WordPress CMS.
  6. Optional but may be important for you: Also make sure you put your website to a frozen state or maintenance mode. This is quite necessary if your site involves users to add something to your site (e.g: posting comment in blog, posting and replying in a forum thread, and so on). I will not tell you how to do that as this may vary according what kind of script your website is using. In WordPress, you can simply use a plugin called “code-freeze” which you can download here.
  7. Before you really proceed, make sure, again, make sure your new server is really really ready to host your website.
  8. Also, make sure your domain name still resolves to old host not to the new server. You better change your domain’s NS record later after the website is migrated.

The Web Migration Method

Step 1 – First thing first, we have to find a way how to transfer all files from your old host to new server. There are two main ways you can accomplish this mission: First, by creating full backup of your website files; Secondly, you can use ftp let your new server to access all files in old host. Whatever the way you will use, the first step here is simply login to your old host cPanel area.

These earlier steps will use the first way (manually). You can scroll down this page and find the “Alternative Way To Move Files” section.

login cPanel

Step 2 – This step shows you how to create backup of all your files. In cPanel, launch “File Manager”.

open file manager

Step 3 – Next, go to your cPanel’s File Manager area and click “Select All” option. Optionally, you may also exclude files/folders from backup by pressing and holding Control key on your keyboard then click on files / folders you wish to exclude. In this example I exclude cgi-bin folder and .ftpquota file.

file manager

Step 4 – Once done, hit the “Compress” icon then choose “zip archive” in Compression Type. Once done, also give the backup file a name then hit the “Compress Files” button. Sit tight and wait for it to finish. It depends on how many files you have.

select all files and folders

In this example my backup file name is “wp-admin.zip”.

name a file

Step 5 – Login to your new server via SSH. I will not explain it again as I assume you knew it already, otherwise just ask me how in the comment section below and I’ll show you separately. It is recommended to login to your new server with root privilege.

Step 6 – In your new server, go to the root folder of your site’s document. It usually is “/var/www/domain.com/public_html” or “/var/www/domain.com/htdocs”. Read my previous guide about most common Unix commands needed to navigate inside your server.

example:

cd /var/www/servermom.com/htdocs

cd var www

Step 7 – Now it’s time to download the backup file you’ve created. And here’s the web migration is actually happening. Use the “wget” command:

wget http://domain.com/path/to/file.zip

example:

wget http://servermom.com/wp-admin.zip

wget backup file

Step 8 – So all your files have been transferred to the new server minus its database. But that’s just yet. Now all you have to do is extracting the backup file using unzip command. Read: how to zip and unzip in Linux-based server.

unzip filename.zip

example:

unzip wp-admin.zip

it will give output like this:

unzip file

Once done, you can check all files and folders list by typing “ls” command then hit Enter.

list files folders

Step 9 – Alright, it is time to also move your site’s database. Go back to your old host cPanel area then click the “Backup Wizard” icon.

backup wizard

Next, click the “Backup” button.

click backup

Next, click the “MySQL Databases” option under “Select Partial Backup” section.

click mysql database

In the next page you’ll see all available MySQL database. Unfortunately in this example I only have one 🙂

mysql database

Next, right-click on the database link and copy that link / url (you may also paste it to notepad first).

copy link

Step 10 – Now go back to your SSH client. I assume you are still in “/var/www/domain.com/public_html or /htdocs” then issue following command:

wget --user=cpaneluser --password='cpanelpass' http://domain.com:2082/cpsessxxxxxxxx/getsqlbackup/filename.sql.gz

note:

  • Change “cpaneluser” with the username of your old host cPanel username
  • Change “cpanelpass” with cPanel password.
  • Change “http://domain.com:2082/cpsessxxxxxxxx/getsqlbackup/filename.sql.gz” with database link copied in step 9 above.

example:

mysql dump

Next, extract it using this command:

gzip -d filename.sql.zip

Once done, you should now get filename.sql

Failed with that method? Alternatively you can simply download your database “.sql.gz” file to your computer, upload it again to your old host via File Manager, then transfer it to new server using wget command:

wget http://domain.com/filename.sql.gz

Step 11 – Next, lets import that .sql file to your server’s database. First, make sure you create new MySQL database and MySQL user on your new server and grant all access for that user to the database. Once done, use this command:

mysql -u MYSQL_USER -p DATABASE_NAME < DATABASE_NAME.sql

Please replace:

  • MYSQL_USER with your own MySQL username. This is not your server username or root.
  • DATABASE_NAME with the actual database name in your server you wish to use. You can simply create and use the same database name as your old host.
  • DATABASE_NAME.sql with the .sql file transferred to your new server using step 10 above.
  • Confused? Read our previous guide about how to create new user and new database and grant access on: Here, here and here.

Step 12 – All the geeky things are all above. The next step you have to simply edit your script to reflect new server settings including editing database name, user and password in your script (if you use different database name).

Alternative Way To Move Files

Instead of creating a .zip file of your files in old host then transfer it to new server using “wget” command followed by unzipping it, there is also another method to migrate all your website file from cPanel to new server using ncftp method.

Issue this command to install ncftp on your new server:

apt-get install ncftp

or use yum on CentOS or Fedora:

yum install ncftp

install ncftp

next, make sure you are in your server’s root document (public_html or htdocs), if not, go in there..

cd /var/www/domain.com/htdocs

once done, note down your old host ftp username and password. You can find it in cPanel via “FTP Accounts” menu.

ftp account

usually your cPanel username and password is also the same as your ftp account. Now go back to your SSH client and issue this command syntax:

wget -nc -r --no-parent ftp://ftp.domain.com/public_html  --ftp-user=username --ftp-password=password

or you can use your ip:

wget -nc -r --no-parent ftp://123.123.123.123/public_html  --ftp-user=username --ftp-password=password

change “username” with your own ftp username and “password” with corresponding password. Once done, issue that command in your new server. Sit tight and wait till the process finished as it should take few minutes and it depends on how many files you have. Once finished, you’ll see something like this:

ncftp finish

Now you can issue “ls” command to see the files. In my case, instead of seeing the files, I got a folder called “ftp.servermom.com”. If you do so, simply navigate to that folder until you see the files.

cd ftp.servermom.com
cd public_html

then issue “ls” command again and you should now see all your files and folders there. Now you have to move all the files and folders to upper level, 2 levels actually. issue this command

mv * .[A-Za-z0-9]* /var/www/domain.com/htdocs

Now your files and folders should be moved from inside “public_html” folder to your document root folder which is “/var/www/domain.com/htdocs or /public_html”.

list file

Next, you can simply delete the “ftp.domain.com” folder using this command:

rmdir ftp.domain.com

However the directory name “ftp.domain.com” could be another name. replace that with your own. If the command above returns with error / could not remove the directory, that;s because the directory is not empty. Double-check it.

If everything’s just fine, you can then proceed to step 9 above to migrate your site’s database.

What’s Next

So you now moved all your website from old host to new server. What’s next? Of course to change the NS entries of your domain with the servers’ IP. If you followed my tutorial about how to setup BIND9 DNS server, that record should be ns1.domain.com and ns2.domain.com. Otherwise you can use your registrar’s DNS manager and update its A record to your server.

My two cents: before you really updating DNS entries of your domain, you better give your server a preliminary test or a dry run. Simply edit your local hosts file (in your computer) and add following entries:

123.123.123.123   domain.com
123.123.123.123   www.domain.com

change 123.123.123.123 with your server’s IP and domain.com with your own domain name. Once done, save it. Now open your browser then try to browse your website by typing your domain name there. Try hitting Control+F5 to hard refresh the page because your browser may still displaying your site from cache. Once you are really sure that everything is fine, you can then update DNS records of your domain.

Still confusing? Please tell me which part of above guide that makes you confused.

7 Comments

Add a Comment

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe and get interesting stuff plus faster updates to your email.