Back to home

Migrate website files/databases to new server

This article shows you how to migrate the websites on a site-per-site basis. Please replace YOURDOMAIN with the domain you would like to migrate. Make sure that you have already created the virtual host configuration on your new server before you start.

Preparation

To ensure a fast migration we suggest to prepare the following configurations.

  • In case there is an existing .htaccess in your webroot please make a backup as this will be overwritten.

DNS

  • We recommend to lower the TTL DNS settings for all domains and subdomains by 300 seconds. Like this, changes will be replicated and distributed faster.

Maintenance page

  • It is important that you do not change any data during the file and database transfer. Otherwise you will end up with incomplete or corrupted data. Therefore we recommend to “disable” the website with a maintenance page. Save the following content to a HTML file called /home/www-data/YOURDOMAIN/maintenance.html. You can use any preferred message for this page:
(DE) Seite wird gerade gewartet. Bitte versuchen Sie es später noch einmal.<br>
(EN) Page is under maintenance. Please check back later.
  • Additionally, please prepare a .htaccess file for redirecting to the maintenance page:

/home/www-data/htaccess_maintenance :

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteRule .* /maintenance.html [R=302,L]

Proxying to the new server

You have to prepare a configuration so that the old server acts as a reverse proxy. Like this you make sure that requests sent to the old server will be handled by the new server. This configuration is needed until the DNS changes are fully distributed in the internet. This takes usually up to one day.

  • Create a .htaccess file called /home/www-data/htaccess_proxy with the following content:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [P]
ProxyPassReverse / http://%{HTTP_HOST}/


The migration

  • Please activate the maintenance page to prevent any changes during the migration.
cp /home/www-data/htaccess_maintenance /home/www-data/YOURDOMAIN/.htaccess
  • Now wait for approximately 5 minutes to make sure that uploads, that were already in progress, are finished.

  • Then start the transfer of the files with rsync:

rsync -avzH /home/www-data/YOURDOMAIN/ \
NEWSERVER:/home/www-data/YOURDOMAIN
  • Meanwhile you can migrate the MySQL files as follows: (Please replace YOURDATABASEUSER, DATABASENAME and NEWSERVER with the corresponding value.)
mysqldump --user=YOURDATABASEUSER --password DATABASENAME | \
ssh NEWSERVER mysql -u YOURDATABASEUSER -p DATABASENAME
  • After ‘mysqldump’ and ‘rsync’ are finished connect to the new server and replace /home/www-data/YOURDOMAIN/.htaccess with your backuped one.

  • Now test your website using the following URL “http://YOURDOMAIN.NEWSERVERNAME.nine.ch/”.

  • If everything works as expected you can proceed installing your prepared reverse proxy configuration on your old server.

cp /home/www-data/htaccess_proxy /home/www-data/YOURDOMAIN/.htaccess
  • As a last step please change your DNS records to point to the new server.

  • After about a day, please remove the reverse proxy configuration from your old server and check if everything is still working as you expect it to.



If you have questions or need any assistance do not hesitate to contact our support you can reach us under support@nine.ch or +41 44 637 40 40 .

Didn't find what you were looking for?

Contact our support:

+41 44 637 40 40 Support Portal support@nine.ch