Use the power of cPanel/WHM command line scripts

cPanel / WHM comes with a sleek (in a geeky way) Web interface. Which you don't have to use.

cPanel / WHM comes with a sleek (in a geeky way) Web interface. Which you don't have to use.

cPanel is a ubiquitous Web site control panel, one of the most commonly offered by Web hosting companies. If you have a VPS (Virtual Private Server) or a dedicated server account and you’ve ordered cPanel as a choice of the control panel, you are normally getting cPanel & WHM – a special package for self-administering an Internet server. It has pretty much every feature you would need to support, operate or upgrade your server, all with a (rather busy) Web interface.

I like Web interfaces as much as the next admin but sometimes the operations you need to perform take a mighty long time and the cPanel’s own built-in Web server (Apache 1.3) times out. Alternatively, you may not have access to any Web browser at all. Or, you may be addicted to retro-styled terminals (if you’ve reconfigured your terminal window to show bright green characters on black background, it’s usually a reliable sign of the latter). Whatever the reason may be, cPanel comes with the number of scripts that you can run in your terminal and perform the same tasks that the Web interface lets you perform. And more efficiently, I might add, because all the Web interface does is invokes these scripts and passes all the needed parameters to them, which we can do just as easily from the command line. So, here is how we do it:

Everything you’ll read below assumes you have SSH root access to your server. Regardless of your use of these cPanel scripts, having SSH root access to a VPS or a dedicated server is so essential that it’s practically a given that you have it. If you don’t, it’s time to move your business elsewhere.

cPanel installs a bunch of scripts in the /scripts (which is a symlink of /usr/local/cpanel/scripts/) directory on your server. The scripts are too numerous to describe them all (621 according to ls /scripts | wc ) but there are some of them that are most useful when used from command line. These are mostly scripts that run a very long time and don’t have much interactivity, so you can start them and go get some coffee or do other stuff.

Moving accounts from one server to another just happens to be one of those long tasks that just beg for the use of command line scripts. So, to move an entire account – the website, the email accounts, databases etc. with all the passwords and permissions kept intact we first create an archive file by running

on the old server:
/scripts/pkgacct 'account'

where ‘account’ is the name of the account we’re moving (side note: cPanel often takes the first 8 letters of the domain name as the default and most admins just confirm it).
This will run a long time, packaging all neatly together and creating a gzipped archive file called something like cpmove-account.tar.gz. This file will be created in the /home/ directory.
Then we copy that file to the new server.
on the new server:
scp /home/

This command (scp – secure copy over SSH) will transfer the file and deposit it into the /home/ directory on the new server. All the account moving scripts are setup to look for the archives in the /home/ directory.

When the transfer is complete, run
on the new server:
/scripts/restorepkg 'account'

This will create the home directory (/home/account/), create the user account, email accounts, databases and everything just like it was on the old server. All we have to do after that is to switch nameservers for your domain from the old server’s nameservers to the new and then (after some time has passed and everything is working well on the new server) run this
on the old server:
/scripts/killacct 'account'

That will remove every trace of the site ever being on the old server.

Please note that the description below is not really intended to be a replacement of the official cPanel manual because the scripts are accepting various parameters that control the outcome of the procedure. In most cases the defaults with empty parameters do the job just fine. However, if you find yourself in a situation where you need to change account name on the new server or change the process in some other way, head straight for the cPanel’s official manual and review the parameter options you need.