How To: Transfer Web Hosts

Transferring your site to a new webhost doesn’t have to be a pain, today I’m going to provide you with an easy to follow guide for backing up your website and changing webhosts.  This tutorial will guide you through using SSH, FTP, Pligg and phpMyAdmin methods for moving your data to a new server. These methods are not the only options for backing up your site, but they are some of the most commonly used and available methods. The tutorial seems long, but use the titles to skip sections that don’t apply to the method you choose for backing up your site.Before beginning let me quickly outline the two items that need to be saved when you want to backup your website. The first part is usually pretty obvious, the files on your server need to be saved to your computer and moved to another webhost. The second item is the data used to populate your site with stories, users, votes, settings and a variety of other information. This information is stored in a MySQL database on your web host and is kept separate from normal files.

Use SSH to Backup Your Files and MySQL Database

SSH is a secure method for connecting to your server. SSH is an interface where you can type in commands that will be processed by your server. SSH offers the absolute quickest way to perform a backup of your site, which is why it’s the first method described in this tutorial.

Unfortunately SSH isn’t a graphics based method for making changes to your site so you will need to have a few lines of commands written down until you learn the basics. If you were using computers about a decade ago you might remember using the dull black screen and white text of DOS, which is a similar experience to using SSH.

Putty Config

To access your server using SSH from a PC I suggest downloading the program PuTTY which is used in the screenshots for this article. Mac users are fortunate enough to already have a program installed called Terminal that can do the same thing as Putty. And if you are a Linux user you are probably already familiar with using a command line interface and I’m sure you already know what program you should be using.

The first step with Putty is to connect to the server. Looking at the image above, I’ve opened up putty.exe and have typed in the target domain into the Host Name field. I will then click Open and the window will turn into a command line interface seen below. It will then ask me for my username. After typing in your username (usually your FTP username) hit enter on the keyboard and it will then prompt you for a password. As you type your password you won’t see the text input advance. Don’t worry, your keyboard is still working so continue typing and hit enter when you finish. If you have a typo it will let you try the password again until you get it right.

putty1

Once you successfully log in it will show a line like the last one shown above (I’ve blurred out my domain in the example). To test what folder you’ve logged into on your server type in “ls” (ignore the quotes) and hit enter. It will then list all of the files in the current directory so you can get your bearings. You can then navigate around using the command “cd folder_name” to advance a folder or “cd ..” to go back a folder. For this tutorial I suggest you navigate to an area that is accessable via FTP, but not publicly viewable. Publicly viewable means that it’s not a folder that people on the web can access. Once you’ve found

mysqldump -u username -p database > pligg_backup.sql

It should take anywhere from 5 seconds to 5 minutes to run this command, depending on the size of your MySQL database.  When it finishes you should see a new pligg_backup.sql file in the directory you issued the command from. If you want to refresh the directory listing from SSH type in “ls” and hit enter for it to list all of the files in the current directory.

Now that you have the sql saved as a file you might want to consider compressing it to shrink the size of the file and make it easier to download. zipping the file will probably reduce the size of your .sql file to about half the size of it uncompressed. To compress the file just type the following command into your SSH program.
zip -r pligg_backup_sql.zip pliggbackup.sql
This next step will compress the folder your Pligg installation is located at. You will need to change the last part so that it points to the folder where Pligg is installed relative to what directory you are currently viewing from SSH. In the below example Pligg is installed in the public_html folder that is one level up from the directory I am currently browsing.
zip -r pligg_backup_files.zip public_html/
Once you have your files backed up to your computer and you verify that they are all valid you can upload the pligg_backup_files.zip file to your new web host where you want to install Pligg at and then open up SSH to the directory where you uploaded the  file and run this command to unzip the file.
unzip pligg_backup_files.zip

Use FTP to Backup Your Files

FTP is one of the first technologies that web admins pick up because it’s an easy to use method for adding and removing files from a web host. FTP is limited though and does not offer features such as zipping and unzipping files on your server, which is a critical feature if you want backing up files to be a speedy process. Programs like WinSCP are able to offer some of the benefits of a GUI FTP interface along with archiving (and sometimes unarchiving) abilities, so for the sake of speed I suggest using WinSCP to zip files before downloading.Unfortunately a lot of servers won’t allow WinSCP to extract files using this method, so uploading files to the new web host will be a much slower task than downloading them.

WinSCP Zip

FTP isn’t a solution for backing up your MySQL data so you will need to couple FTP with a tool like phpMyAdmin to make a backup of your MySQL data.


Use phpMyAdmin to Backup Your MySQL Database

If you haven’t used phpMyAdmin in the past, this tutorial shouldn’t be a problem. phpMyAdmin offers a great interface for modifying, importing and exporting your MySQL database and it’s a great tool that web admins should learn sooner than later. Most web hosts offer it as part of their standard hosting features because it’s the most common graphical user interface method to modify your database. To access your phpMyAdmin panel you will need to either enter the server address where your MySQL is stored (ex. mysql.domain.com) or find a link to phpMyAdmin from your web host admin page. Cpanel has a link at the bottom of the MySQL page if memory serves.You will log in to phpMyAdmin using the MySQL username and password that you set up when creating a MySQL database. Once logged in you might need to select the database from a drop down menu or list of databases on the left side of the screen. Once you have selected the database name that you want to backup click on the “Export” tab on the top of the right side of the screen.  Then click on the “Select All” link to make sure that all of the tables in the database are going to be saved.

phpmyadmin_export

The last step is to go to the bottom of that page and click on the “zipped” option to compress the sql and click the Go button to download the .zip file to your computer.

phpmyadmin_save

That’s it for backing up your MySQL database for Pligg. One final note though for those who are attempting to use phpMyAdmin to backup large databases. I’ve discovered that when your database becomes rather large phpMyAdmin won’t be able to export successfully, which is why I recommend using SSH for backing up sql.

Use Pligg CMS to Backup Your Files and MySQL Database

Last but not least is a built in tool offered by Pligg Content Management System that makes backing up your site as simple as 3 clicks. Navigate to your admin panel and click on the Backup tab in the main navbar.

pligg-backup

Click on the 3 links to backup your files, avatars and MySQL database and as you click on each one it should generate a new file at the bottom of the page. Download the 3 generated files and save them to your desktop and be sure to check that the zip files contain the correct information.  When you confirm that the downloads are complete and correct click on the Remove link from the backup page to delete the backup files from your server. I suggest using the Pligg backup method as a secondary option just so that you don’t keep your eggs all in one basket.

The New Webhost

Lets take a quick moment to discuss domain name servers. When you manage a domain you have tell the domain where it should look for hosting to connect to. Name servers are used to point the domain toward the proper host to show the official content for that domain. When you move hosts you will need to edit your name server settings for the domain so that they point to the new host. Making these changes can take “up to 72 hours” for everyone on the internet to be properly pointed to the new web host. However I have never had to wait more than an hour for me to see the changes take effect, but the propagation time will be different depending on your internet service provider (ISP). As an example Comcast cable subscribers might see your old web host while Road Runner cable customers might see the new host.Hopefully your webhost will allow you to upload the files and set up MySQL databases without having the domain name servers transferred. This will allow you to upload all of the files and make sure that everything works before doing the name server switch to point everyone to the new host. Some web hosts allow you to set up a free subdomain (Dreamhost uses a subdomain.dreamhosters.com format) other hosts have an IP address that you can navigate to so that you can see the new server before changing name servers. You should set up your site and confirm that everything is working before changing the name servers for your domain.After you have the Pligg files uploaded to your host you will need to edit a few files so that Pligg will be able to connect with your new MySQL database. Open up /libs/dbconnect.php and edit the values for lines 2-5 to match your new MySQL database.
<?php
define("EZSQL_DB_USER", 'username_here');
define("EZSQL_DB_PASSWORD", 'database_password_here');
define("EZSQL_DB_NAME", 'database_name_here');
define("EZSQL_DB_HOST", 'localhost');
if (!function_exists('gettext')) {
function _($s) {return $s;}
}
?>
If you have changed the domain or what folder Pligg is installed in you will also need to edit the /settings.php file to reflect the changes. Make sure though that after you get the site running that you also change the “Location Installed” settings from the Admin > Configure page of Pligg because this file will frequently update itself using the database settings.
<?php
$my_base_url = 'http://YOUR-DOMAIN.com';
$my_pligg_base = '/subdirectory'; // remove /subdirectory if installed on the site root
$dblang = 'en';
define('table_prefix', 'pligg_');
include_once mnminclude.'settings_from_db.php';
?>
Besides uploading all of the files you will need to import the MySQL into the database. You will need to log in to the new host’s phpMyAdmin page and navigate to the Import tab (next to the export tab used earlier). Select the zip file you saved earlier from either using phpMyAdmin or from using SSH and upload it to phpMyAdmin. Unless the size is too large it should only take a few minutes to upload and add all of the tables to your database.Navigate to your Pligg site’s admin panel and everything should be working. As mentioned a few paragraphs ago you may need to edit a few options from the Admin > Configure page at this point. After you confirm that everything is working go ahead and change those name servers from your domain management page so that your domain will begin to point to the new host.

One thought on “How To: Transfer Web Hosts

  1. great, Excellent, wonderful

    This tutorial really helpful me for transferring my web host. but I have still little error.

    see above in this tutorial “Use Pligg CMS to Backup Your Files and MySQL Database”

    mysql database is so big about 500MB and while I try to back up, it will give error like below.

    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 23593612 bytes) in libs/backup.class.php on line 222

Comments are closed.