Moving a Drupal site to a new host

Moving a Drupal site to a new host is quite easy. It can be summarized as just two steps - backing up the MySQL database and the web-site root directory and storing these on the new host.

Backing up the website files at current host

Login as the administrator in your website at the current host. From the administration menu, flush all caches.
Take backup of the website's MySQL database,

mysqldump --user=website-drupal-user --password=“Drupal-user's-mysql-password” --result=my-website-db.sql website-drupal-database

Change directory to the root directory for the website. Make a tarball for the website directory tree.

cd website-root-directory
mkdir ../tmp
tar -cvzf ../tmp/website.tar.gz .

It is important to end the last command with a dot. tar should make an archive of the current directory tree. If you replace the dot with *, it is an error as the .htaccess and other files starting with dot will be left out.

Installing the website on the new host

On the new host, login into the MySQL shell as root and delete the previous website-drupal-database, if it exists. Also drop the user, website-drupal-user, if exists. Then create a new database, website-drupal-database. Grant all privileges on website-drupal-database to website-drupal-user. Then, login to MySQL shell as user website-drupal-user and restore from the database backed on the earlier host.

$ mysql -u root -p
mysql> drop database website-drupal-database;
mysql> create database website-drupal-database;
mysql> grant all on website-drupal-database.* to 'website-drupal-user'@'localhost' identified by “Drupal-user's-mysql-password”
mysql> quit
$
$ mysql -u website-drupal-user -p
mysql> use website-drupal-database
mysql> source my-website-db.sql;

Next, un-tar the website files in the website root directory,

cd website-root-directory
tar -xvzf website.tar.gz

Assuming that you have done the web server related configurations, the website should be operational after this. Please note that we have taken care to keep the website's MySQL database name and the database user-id and password the same as before. If any of these change, corresponding changes have to be made to the file, sites/default/settings.php.

Make a tmp directory outside the site's root directory. Make it writable by www-data. Open the page /admin/config/media/file-system in the browser. Set the Private file system path. Also, ensure that the package php5-mysql is installed.

See also

Software: