How to Migrate your Web Hosting to Another Datacenter at Gandi

Migrating a site from a web hosting to one located in another datacenter can be done in a few steps:

  1. Backup the source code of your website(s) as well as the database(s),

  2. Create the new Web Hosting in another datacenter,

  3. Remove the virtual host from the old web hosting and recreate it on the new web hosting,

  4. Upload the source code of the website(s) to the new web hosting and import the database(s),

  5. Edit the domain’s DNS records to point the website to the new web hosting.

This procedure will cause a service outage of a few hours due to the modification of the DNS records. In addition, it will be necessary to remove the virtual host on the existing web hosting before you can recreate it on your new web hosting. To reduce this downtime, you can reduce the TTL of the DNS records that are related to your web hosting 24 hours prior to beginning this process.

Backup Website Files

You will need to download the website files and database of the virtual host of your web hosting using an sFTP client, such as FileZilla.

To connect to your SFTP Web Hosting, you will need to know the following information:

  • Host: sftp.sdX.gpaas.net

  • Port: 22

  • User: Your unique identifier. A multi-digit number, provided in the confirmation email sent when creating your web hosting, also visible on the management page of your web hosting. Be careful, ** it’s not ** your Gandi username.

  • SFTP Password: The one you defined when creating your web hosting. If necessary, you can change this password from the Password Management section of your web hosting.

Note

You can find the Host and User ID by navigating to the Sites section of your web hosting, then click on the Site you wish to connect to and locate the sFTP section on its Sites page.

Export databases

To export your databases, several solutions are available to you. You can use a database management interface, such as phpMyAdmin, or the MySQL command line when connecting through the SSH console of your web hosting.

Example with phpMyAdmin

  1. Go to your Web Hosting Control Panel to access phpMyAdmin,

  2. Then select the database to export in the left column, and click on the ‘Export’ menu at the top of the page,

  3. Choose the ‘Fast’ export method and leave the other option at their defaults,

  4. Finally, click ‘Run’ to download the ‘.sql’ format file to your local computer.

Example with the MySQL Command-Line

Login to the SSH console of your web hosting.

Navigate to a directory where you have write permissions, such as /srv/data/tmp/, using the following command:

$ cd /srv/data/tmp

Then run the following command to export the database to a file:

$ mysqldump -u root -p name_of_base> name_of_base.sql

An ‘.sql’ file corresponding to the database will then be created in the ‘tmp’ directory of your web hosting, and you will be able to download it via sFTP at the path /lamp0/tmp/.

Create the New Web Hosting

You can now create your new web hosting.

Remember to select the desired datacenter location you want your website hosted from.

Delete the Old Virtual Host

Note

This operation will result in a service interruption because the files on the site in production will be deleted. This step is necessary to release the virtual host so that is can be declared on your new web hosting.

  1. Go to the management interface of your web hosting to delete the relevant virtual host,

  2. In the section labeled ‘Sites’, select the vhost, and then click on the “Delete” button,

  3. The deleted virtual host files will be placed in the ‘trash’ directory, allowing you to restore the files in case of problems. To access the ‘trash’ directory via sFTP, navigate to the /lamp0/trash/ path. Via SSH console, use the /srv/data/trash/ path.

Also remember to delete the virtual host files from the trash directory when the migration is completed in order to free up space on your disk.

Create the New Virtual Host

The virtual host is now released, so you can recreate it on the new web hosting.

You can also configure your domain’s DNS records to point to website’s address the new web hosting.

Upload Your Files to the New Web Hosting

With the virtual host created, you can now upload your files to the new web hosting via sFTP.

Note to Git Users

If you deployed your application code via Git, you can add a new remote repository using the git remote command and then push/deploy the code to the new web hosting.

You will be able to deploy the code on your new web hosting using the following commands, assuming you are already in the working directory of your local repository:

$ git init
$ git remote add new ssh + git://{login}@git.dc2.gpaas.net/{vhost}.git
$ git add htdocs
$ git commit htdocs
$ git push new master
$ ssh {login}@git.dc2.gpaas.net 'deploy {vhost} .git'

Import Databases

In the same way as the database export, you can use phpMyAdmin or the MySQL command-line to import your database(s).

Example with phpMyAdmin

  1. Go to your Web Hosting Control Panel to access phpMyAdmin.

  2. Click on the “Databases”” menu at the top of the page.

  3. Specify the name of the database into the “Create Database”” field.

  4. Then select the database that has just been created in the left column, then click on the “Import”” menu at the top of the page.

  5. Choose the ‘.sql’ file to import from your local computer with the ‘Browse’ button.

  6. Finally, click ‘Run’ to import the ‘.sql’ file.

Example with the MySQL Command-Line

First, upload the ‘.sql’ file via sFTP into the tmp directory of your new web hosting.

Login via the SSH console, then navigate to the /srv/data/tmp/ directory.

$ cd /srv/data/tmp

Then run the following commands:

$ mysql -u root -p
mysql> CREATE DATABASE name_of_database;
$ mysql -u root -p name_of_database < name_of_database.sql

Deleting the Old Web Hosting

The migration is now complete, so you can delete the old web hosting if you are no longer hosting any other websites on it. Your Gandi prepaid account will automatically receive a pro-rated reimbursement for the remaining time of the current subscription, which can be used for future Gandi purchases.

Migration Service

If you do not want to perform this migration on your own, we offer a migration service managed by a partner who will support these operations. If this offer interests you, we invite you to contact support for more information.