Moving a CPanel website over SSH

What’s the best way to move a website to a new server? Here’s the method I used, requiring SSH on both servers (which I have).

Host A old one with files.
Host B new one.

Log into A via SSH and create archive with all your data.

Code:
tar -cf myfiles.tar directory_name_with_your_files (ex. public_html)
gzip myfiles.tar

Copy myfiles.tar.gz to your public_html directory.

Code:
cp myfiles.tar.gz public_html/

Then login into B via SSH also and download your archived website and unpack file.

Code:
mkdir old_site
cd old_site
wget http://www.yourdomain.com/myfiles.tar.gz
tar -zxvf myfiles.tar.gz

Now you should copy unpacked files somewhere ex. public_html using “cp” command or “mc” (Midnight commander) if available.

Source

And for MySQL:

$ mysqldump -p -u username mydatabase > mydata.sql

Once copied onto the new server your can populate your new database with the mysql command:

$ mysql -p -u username mydatabase < mydata.sql

Source

2 Responses to “Moving a CPanel website over SSH”

  1. One addition to this simple but informative article. Here, we use HTTP for transferring the .tar.gz from one host to another. But it is quite easy if we can use SSH for that as there is no additional step involved. For this, one can use “scp” command after connecting via SSH. Find a little description below:

    “scp works just like the standard local Unix copy command, cp, except that you put the name of the remote system, followed by a colon, in front of the pathname specification for the remote file.

    You can copy either direction, to or from the remote system, with scp. If no directory is specified for the remote system, your home directory there is assumed.

    scp will prompt you for the password on the remote computer, or not, depending upon the type of authentication system you have set up for ssh.

    Just like cp, scp will silently remove any existing file that is “in the way” of making its copy, at either end. But unlike cp, there is no -i option that you can use with scp to force it to ask you first before overwriting an existing file. If you think that there is any chance that an existing file may have the same name as the one you trying to copy, you need to check first yourself.”

    • Elliot Lee says:

      Yup, it’s true that you can use “scp” and save one step. It might also be safer, as you’re going through a secure connection. Thanks for that addition!

Leave a Reply