====== How to migrate a (web) server ====== This guide explains the steps to take when migrating a web server to a new machine and/or a new platform. Most of it will also apply to any other type of server. ===== Prerequisites ===== * Source (Pandora): running existing server with Debian 9 installed * Destination (Calypso): basic install of the new server with Debian 11 * A firewall (FW) with port forwards for outside access (e.g. ports 80 and 443) * Make sure both machines have [[deb9:ssh#linux_host|SSH access]] through a private key so you don't need to enter a password * Create a batch file ''ccalypso'' on Pandora to facilitate copying folders and files with the following content:#!/bin/bash if [ "$2" == "" ]; then exit 1 fi sudo rsync -avz -e 'ssh -i /home/user/.ssh/id_ecdsa -p 22' --rsync-path='sudo rsync' $1 user@dest.ip.addr:$2 ===== User home directory ===== - Copy folders and files from Pandora$ ccalypso /home/user/folder-or-file /home/user/ - If the UID on both machines are the same you don't need to update folder and file ownership - You can use the same way for any other folder or file you want to transfer from the old to the new server ===== Apache 2.4 ===== - Install [[deb11:apache|Apache 2.4 and PHP 7/8]] on Calypso - Rename folders on Calypso$ sudo mv /etc/apache2/conf-available /etc/apache2/conf-available-debian $ sudo mv /etc/apache2/conf-enabled /etc/apache2/conf-enabled-debian $ sudo mv /etc/apache2/sites-available /etc/apache2/sites-available-debian $ sudo mv /etc/apache2/sites-enabled /etc/apache2/sites-enabled-debian - Copy folders from Pandora$ ccalypso /etc/apache2/conf-available /etc/apache2/ $ ccalypso /etc/apache2/conf-enabled /etc/apache2/ $ ccalypso /etc/apache2/sites-available /etc/apache2/ $ ccalypso /etc/apache2/sites-enabled /etc/apache2/ - On Calypso check and copy selected files back from the debian installed folder to the folder copied from Pandora - If the UID on both machines are the same you don't need to update folder and file ownership - If you have reverse proxies don't forget to update your firewall settings ===== MariaDB ===== - Install [[deb11:mariadb|MariaDB 10.5]] on Calypso - On Calypso, dump the contents of the ''mysql'' database$ mysqldump -u user -p --opt mysql > mysql.sql - Stop the mysql service on both machines$ sudo service mysql stop - On Calypso, rename the db folder$ sudo mv /var/lib/mysql /var/lib/mysql_debian - On Pandora, copy the db folder to Calypso$ ccalypso /var/lib/mysql /var/lib/ - On Calypso, remove the following folders and files$ sudo rm -R /var/lib/mysql/mysql $ sudo rm -R /var/lib/mysql/phpmyadmin $ sudo rm -R /var/lib/mysql/debian-10.1.flag - On Calypso move the following folders and files back from the ''mysql_debian'' folder to the ''mysql'' folder copied from Pandora$ sudo mv /var/lib/mysql_debian/mysql /var/lib/mysql $ sudo mv /var/lib/mysql_debian/aria_log00000001 /var/lib/mysql $ sudo mv /var/lib/mysql_debian/aria_log_control /var/lib/mysql $ sudo mv /var/lib/mysql_debian/debian-10.5.flag /var/lib/mysql $ sudo mv /var/lib/mysql_debian/multi-master.info /var/lib/mysql $ sudo mv /var/lib/mysql_debian/mysql_upgrade_info /var/lib/mysql - Remove folder ''/var/lib/mysql_debian'' - If the UID on both machines are the same you don't need to update folder and file ownership ===== System ===== - Check and adjust crontab for all users and root - Check and adjust the sudoers file and all files in ''/etc/sudoers.d/'' - Check other machines which depend on the webserver, for example a mail server using Let's Encrypt certificates managed by the web server