Transfering our website from one host to another host is always a daunting task. It means a lot of work, small but important. It can also cause your website down for some time, make your website lose traffic. How can we transfer our website seamless, without losing traffic? The principle is moving your files and database firstly, and finally changing your domain’s nameserver setting.

Assuming you are transferring website between linux host, here are the steps and command you should know:

1.Make a zip file of all your website files

If your host use cpanel, your can zip your website directory using filemanager, if not, You can zip your website using linux command.
Log into your new host using shell account. PuTTY is a free tool of Telnet and SSH for Windows and Unix, I recommend you to use it.

cd /home/username
zip -q -r yourdomain.zip yourdomain

Command like this can compress all your website files into one file. Transfering one big file is more efficient than many small files. “/home/username” is the directory of your host account, it may be different in your host.
Attention: if you use absolute path in your shell command like this:

zip -q -r /home/username/yourdomain.zip /home/username/yourdomain

your zip file will contain the whole directory path, that is to say, when you unzip yourdomain.zip, it turns to a home directory including a username directory, username directory includes a yourdomain directory, this yourdomain directory is also your website directory.

2. Backup your database

If your website have a database, you must make a backup. If your use a mysql database,

mysqldump --user=your_database_username --password=your_database_password -h your_database_host yourdatabase > /home/username/yourdomain.sql

Shell command above will make a complete backup of your database.
Attention: at some host, your_database_host is localhost, at others, it’s not, usually you can get all this information in your webiste’s configure file. WordPress’s database connection information is in wp-config.php file.

3. Move all your website files to new host

Log into your new host using shell account, then

cd /home/new_username/
scp username@yourdomain:/home/username/yourdomain.zip
scp username@yourdomain:/home/username/yourdomain.sql

If you put your zip files under public html directory, you can also transfer your website files like this
Log into your new host using shell account, then

cd /home/new_username/
wget http://yourdomain/urlpath/yourdomain.zip
wget http://yourdomain/urlpath/yourdomain.sql

After transfering, unzip yourdomain.zip

4. Change yourdomain directory’s owner to new_username

At your new host, add yourdomain as a primary domain or addon domain, select yourdomain directory as website directory

chown new_username:new_username -R /home/new_username/yourdomain

Using command like above to change yourdomain directory’s owner to new_username. If you didn’t change it, sometimes there is error during your use, such as you cann’t use your filemanager to edit website files.

5. Restore your database using the previous backup

At your new host, build a new mysql database and a new mysql user, connect the mysql user to the database, then restore your database using the previous backup:

mysql -u your_database_username --password=your_database_password yourdatabase < /home/username/yourdomain.sql

You must also change the database configure file of your website. WordPress's database connection information is in wp-config.php file.

6. Change your domain’s nameserver

Finally, change your domain’s nameserver at your domain registrar. After minutes or hours, ping your website, the ip has changed and everything is ok.

It probably takes hours before you can access your website that's because DNS propagation. If there is still some error, it's probably file permission issue, you can use chmod command to solve it.