hyperreal.coffee

Migrating

Install dependencies.

1sudo apt update
2sudo apt dist-upgrade
3sudo apt install apache2 mariadb-server libapache2-mod-php php-gd php-mysql php-curl php-mbstring php-intl php-gmp php-bcmath php-xml php-imagick php-zip php-apcu redis-server

Setup the database.

1sudo mysql
1CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'password';
2CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
3GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
4FLUSH PRIVILEGES;
5quit;

On the original machine, put Nextcloud into maintenance mode.

1cd /var/www/nextcloud
2sudo -u www-data php occ maintenance:mode --on

Wait 6-7 minutes for the sync clients to register the server is in maintenance mode before proceeding.

Stop the web server that runs Nextcloud.

1sudo systemctl stop apache2.service

Copy over the Nextcloud directory to the new machine.

1rsync -aAX /var/www/nextcloud root@new-machine:/var/www

Copy the PHP configurations to the new machine.

1rsync -aAX /etc/php/8.2/apache2/ root@new-machine:/etc/php/8.2/apache2
2rsync -aAX /etc/php/8.2/cli/ root@new-machine:/etc/php/8.2/cli

The PHP version on the new machine must match that from the original machine.

On the new machine, ensure /etc/php/8.2/mods-available/apcu.ini is configured correctly.

1extension=apcu.so
2apc.enable_cli=1

On the new machine, ensure permissions are set correctly on /var/www/nextcloud.

1sudo chown -R www-data:www-data /var/www/nextcloud

On the original machine, dump the database.

1mysql --single-transaction --default-character-set=utf8mb4 -h localhost -u nextcloud -p nextcloud > nextcloud-sqlbkp.bak

Copy the database backup to the new machine.

1rsync -aAX nextcloud-sqlbkp.bak root@new-machine:/root

On the new machine, import the database backup.

1mysql -h localhost -u nextcloud -p -e "DROP DATABASE nextcloud"
2mysql -h localhost -u nextcloud -p -e "CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"
3mysql -h localhost -u nextcloud -p nextcloud < /root/nextcloud-sqlbkp.bak

On the new machine, ensure redis-server service is started.

1sudo systemctl enable --now redis-server.service

On the new machine, run the following command to update the data-fingerprint:

1cd /var/www/nextcloud
2sudo -u www-data php occ maintenance:data-fingerprint

Ensure DNS records are changed to the new machine and the web server is running before taking Nextcloud out of maintenance mode.

On the new machine, take Nextcloud out of maintenance mode.

1cd /var/www/nextcloud
2sudo -u www-data php occ maintenance:mode --off

Reply to this post by email ↪