Free-Webmaster-Tools.com is a collection of tools for your web development needs and insightful articles and tips.

Moving Your Web Site To A New Web Host
Changing web hosting services means moving your web site.
By Steve Shubitz

Sooner or later your going to change web hosting services or your dedicated server provider. Moving your site during this procedure may appear to be a daunting task but it's really very easy if you follow my step by step procedure. You may need to read this article twice or better yet, click the Print this article link at the bottom and use this article as a check list.

Archive your old site including any MySQL data

Forget FTP. This important first step will save you hours and preserve your scripts permissions and MySQL databases. Log into your old site via shell/telnet. Next, run this command which creates an archive of your entire site:

tar -cvf - /hsphere/local/home/user_name/domain.com | gzip -c > /hsphere/local/home/user_name/site_bu/site_backup.tar.gz

Another example:

tar -cvf - /home/user_name/public_html | gzip -c > /home/user_name/site_bu.tar.gz

In the above command, which is all on the same line you need to change the path to your site and the path where you wish to store the archive. Insure that you store the archive outside the folders/site you are backing up. If you don't have a special directory for your backups, use the MkDir command in your FTP client to creat this directory.

In the first example we are backing up all the files in the /domain.com directory and storing the archive outside/above this directory in the /site_bu directory. In the second example we are backing up all the files in the /public_html directory and storing the archive outside/above this directory in the /user_name directory.

If you have MySQL data you wish to back up, run this command from shell:

mysqldump -uusername -pmy_password databasename | gzip -c > /home/user_name/public_html/database_backup.tar.gz

In the above example change: username to the username for the database you wish to back up on your old site, my_password to this databases password, and databasename to the name of the database you wish to back up. Depending on the size of your database this command can take seconds or minutes.

Download your archives

Launch your FTP client and log into your old site. Next, download the .tar.gz archives we just created to your local machine using Binary transfer.

Upload your archives to your new site and MySQL import

Hopefully your new virtual hosting plan includes a dedicated IP number for your exclusive use. Those with dedicated servers normally have this. A dedicated IP number will probably cost more but will permit you to test your new site immediately and may enhance your Search Engine rankings. Upload your .tar.gz archives to your new site inside the /public_html folder using Binary transfer. At the conclusion of your uploads, stay connected to your new site.


Decompressing your archives via shell/telnet

Log into your new site via shell/telnet. Issue the following command to determine where you are:

ls -al

You should see directory names and files on your screen. The next step is to change to the directory where your archives are located. Issue this command:

cd public_html or it might be cd /home/username

Next issue the following command and you should see the file names of your archives:

ls -al

Next, we need to decompress your archives with the following command. Please note, you must be located in the directory which contains these archives.

tar -xzf site_bu.tar.gz (or it might be:)
tar -xzf database_backup.tar.gz


Moving files around via FTP

Hopefully, you are still connected to your new site via FTP. Click the Refresh button and you should see a new folder which is the result of decompressing your archives. Drill down into this folder structure which comes from your old site, untill you reach the web site files. Shift click on all of these files and folders and then select Move files in your FTP client. In the remote destination folder field enter /public_html/ and click OK. Note that this command requires two "/" characters. Navigate back up the directory tree and click your Refresh button and you should see all the files and directories from your old site. You can even test this new site in your browser via the IP number like this: https://216.7.163.213

If you are moving a MySQL database from your old domain, perform all the steps in the previous paragraph. Double check your old sites directory structure to insure you didn't leave any files behind in the move cammand and then select the folder at the top level from your old site and issue the Delete files command in your FTP client.

If you performed these steps correctly all your site files should be located in the correct directory, including your scripts. You should still have your .tar.gz archives which you can deleate. Don't deleate your MySQL "dump" file yet.

Set up your MySQL database for your new site

Log into your new sites Control Panel and create a new MySQL database. Copy and paste the data for this new database into Notepad for future reference and use. You will need all of this data in the next section.

Import your data into your new MySQL database

Log into your new site vis shell/telnet. Issue the following command to see where you are:

ls -al

Next you need to change directories to the location of your database_backup dump file which was contained in the archive. Issue this command:

cd public_html or it might be cd /home/user_name

Verify that you are currently located in the correct directory via this command:

ls -al

You should see the name of your MySQL data file on the screen like this: database_backup.sql In the next step we are going to import your MySQL data into your new database. Note, you must be in the correct directory for this command to work. Issue this command:

mysql -u username -p database < database_backup.sql

Replace username with the username for the database on your new site. Replace database with the name of the database. Replace database_backup.sql with the name of the .sql file. You will be asked for your password before this command will run. Copy and paste it from your Notepad file to insure accuracy. Depending on the size of your database this command may finish in a few seconds or it could take several minutes. You will see a completed notice on the screen. Php/MySQL scripts may require you to edit a file which is sometimes called config.php or config_include.php. This file should contain the current MySQL database data on your new host. Copy and paste the appropriate data you saved in Notepad when you set up the new database. With a dedicated IP, you can test your new database via your browser. Navigate to it's location using your new sites IP number.

Clean up, testing, and tweaks for your new site

If the previous steps worked properly, you can deleate your MySQL dump file and any remaining .tar.gz archives from your site. If your new site uses a dedicated IP you can test the pages with your browser. Some of your scripts will even run properly and others may not because of the following reasons which may require edits:

• Path to Perl is not correct for your new site
Path to sendmail is not correct for your new site
The script includes a domain name variable so you will have to wait for propagation of your domain.
The script includes a server path variable like /home/domain/cgi-bin which you must edit for your new site
Php/MySQL scripts may require you to edit a file which is sometimes called config.php or config_include.php This file should contain the current MySQL database data on your new host. Copy and paste the appropriate data you saved in Notepad when you set up the new database.

Do not cancell your old hosting account yet. This provides you with a measure of protection in case you forgot some files and during the propagation of your new site, some folks will see your old sites and some will see your new site untill propagation is completed.

Changing your DNS/Nameservers and propagation

The final step in this procedure is to change your DNS/Nameserver data with the registrar of your domain. You should not do this untill you are absolutely sure your new site contains all the necessary files and everything is working properly.

Your new host should have sent you an email with your new nameserver data. It will look somethingthing like this:

ns1.host.com 123.4.567.123
ns2.host.com 123.4.567.124

Log into the Admin of your registrar and copy and paste the new DNS/Nameserver data into the appropriate fiedls. The IP number is normally not required for virtual hosting accounts since your host's DNS should be automatically recognized by your registrar. If this is your own dedicated server, you may have to registrer your custom DNS/Nameserver data with your registrar before the change will be accepted. This procedures normally requires both ns1.host.com and the IP number of 123.4.567.123. Save your setting and double check them. You have just started the propagation of your web site. A procedure where the Internet's 13 root servers notify every ISP in the world about the new location of your site. This procedure is rolling in nature and starts within 6 hours but normally takes 24 to 48 hours. In rare cases, it can take up to 5 days with some ISPs.

After you can reach your new site with the domain name and not the IP number, immediately test the site again to insure that everything works. Five days after you started the propagation procedure you can cancell the hosting with your old host.

This article is ©2003 by Free-Webmaster-Tools.com/Published Perfection. All rights reserved. Reproduction in any form is prohibited. Print this article.

Return to Webmaster Tips and Articles Index

Top of Page. Free-Webmaster-Tools.com is a collection of tools for your web development needs and insightful articles and tips.