For example, I will transfer Nextcloud from one Linux server to another and change the domain.

First of all, we prepare a new server, for example, as I described in this article:
Install Nextcloud in Ubuntu
1 2 3 4 5 6 7 8 9 10 | sudo apt-get install apache2 mysql-server php libapache2-mod-php php-json php-mysql php-bz2 php-curl php-gd php-imagick php-intl php-mbstring php-xml php-zip php-memcache php-bcmath php-gmp sudo a2enmod rewrite sudo a2enmod headers sudo a2enmod env sudo a2enmod dir sudo a2enmod mime sudo a2enmod setenvif sudo a2enmod ssl sudo service apache2 restart |
Install an SSL certificate for the domain, for example from Let’s Encrypt.
Let’s set up the web server.
Let’s create a database and import a backup copy of the data into it:
1 2 3 4 5 6 | mysql -u root -p CREATE DATABASE nextcloud; CREATE USER 'nextcloud' @ 'localhost' IDENTIFIED BY 'PASSWORD_ixnfo.com' ; GRANT ALL PRIVILEGES ON nextcloud.* TO nextcloud@localhost; flush privileges ; quit |
1 2 | gzip -d nextcloud.sql.gz mysql -D nextcloud < nextcloud.sql |
Copy the Nextcloud files (and the data directory if it is placed separately):
1 2 | rsync -avh -e "ssh -p 222" --delete cloud@ixnfo.com:/var/www/cloud/ /var/www/cloud/ rsync -avh -e "ssh -p 222" --delete cloud@ixnfo.com:/srv/hdd/nextcloud/data/ /srv/hdd/nextcloud/data/ |
If there are a lot of files, then I recommend running the copy process in screen so that you can disconnect from ssh (Ctrl+a d to disconnect from the terminal, -r to connect):
1 2 | screen -S nextcloud screen -r nextcloud |
If necessary, change the domain name in the configuration /config/config.php
1 2 3 4 | 'trusted_domains' => array ( 0 => 'ixnfo.com', ), |
If apache2 is installed, then most likely OPcache cached the old domain name, so we will restart apache2 to update:
1 | service apache2 restart |
Now it remains to enter the Nextcloud web interface and, if necessary, update to the latest version (if after the update you need to add indexes in the database, then add them):
1 2 | cd /var/www/nextcloud sudo -u www-data php occ db:add-missing-indices |
During Nextcloud migration, you can enable maintenance mode:
1 | sudo -u www-data php occ maintenance:mode --on |
See also my articles:
Nextcloud. Migrating the DATA directory