Migrate Owncloud to Nextcloud

https://nextcloud.com/migration/

Ubuntu 16.04

Automigration did fail at deleting old files (Delete old files; Could not unlink: xxx ...)

Change DNS name. e.g. nextcloud.example.com

  • cd /var/www
  • Backup:
    • cp -a owncloud owncloud_backup_`date -I`
    • mysqldump --add-drop-table owncloud > owncloud_backup_`date -I`.sql
  • apt-get install apache2 mysql-server mysql-client php php-cli libapache2-mod-php php-mysql php-gd php-json php-curl php-mbstring php-intl php-imagick php-xml php-zip unzip php-bz2 php-mcrypt php-gmp php-redis php-cli php-common
  • sudo -u www-data php owncloud/occ --version
  • wget https://download.nextcloud.com/server/releases/latest-10.zip

  • unzip latest-10.zip

  • chown -R www-data:www-data nextcloud

mysql

  • mysql -e "CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;GRANT ALL ON nextcloud.* to nextcloud@localhost IDENTIFIED by 'mypassword';FLUSH PRIVILEGES;"
  • vi /etc/mysql/my.cnf
    • [mysqld]
      innodb_large_prefix=on
      innodb_file_format=barracuda
      innodb_file_per_table=true
      
      character-set-server=utf8mb4
      collation-server=utf8mb4_general_ci
      
      [client]
      default-character-set=utf8mb4
      
      [mysql]
      default-character-set=utf8mb4
  • service mysql restart

apache / php

  • a2enmod rewrite headers env dir mime ssl
  • vi /etc/php/7.0/apache2/php.ini
    • opcache.enable=1
      opcache.enable_cli=1
      opcache.interned_strings_buffer=8
      opcache.max_accelerated_files=10000
      opcache.memory_consumption=128
      opcache.save_comments=1
      opcache.revalidate_freq=1
  • vi /etc/apache2/sites-available/tempPort80.conf
    • <VirtualHost *:80>
          ServerAdmin admin@example.com
          ServerName example.com
          ServerAlias www.example.com
          DocumentRoot /var/www/html
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
  • echo "Nothing to see here..." > /var/www/html/index.html
  • a2ensite tempPort80
  • vi /etc/apache2/ports.conf
    • Uncomment "Listen 80"
  • service apache2 restart

letsencrypt

  • add-apt-repository ppa:certbot/certbot
  • apt-get update
  • apt-get install python-certbot-apache
  • certbot certonly --apache -d nextcloud.example.com

nextcloud apache vhost

  • vi /etc/apache2/sites-available/nextcloud.conf
    • <VirtualHost *:443>
              ServerName nextcloud.example.com
              ServerAdmin office@example.com
              DocumentRoot /var/www/nextcloud
      
              ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
              CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
      
              SSLEngine on
              SSLCertificateFile /etc/letsencrypt/live/nextcloud.example.com/fullchain.pem
              SSLCertificateKeyFile /etc/letsencrypt/live/nextcloud.example.com/privkey.pem
              Include /etc/letsencrypt/options-ssl-apache.conf
      
      
              <Directory /var/www/nextcloud/>
                      Options +FollowSymlinks -Indexes
                      AllowOverride All
      
                      <IfModule mod_dav.c>
                              Dav off
                      </IfModule>
      
                      SetEnv HOME /var/www/nextcloud
                      SetEnv HTTP_HOME /var/www/nextcloud
      
                      Header always add Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
              </Directory>
      </VirtualHost>
  • a2ensite nextcloud
  • service apache2 restart

nextcloud with confg and data from owncloud

  • cd /var/www/nextcloud
  • cp -a ../owncloud_backup_`date -I`/config/config.php config/
  • vi config/config.php
    • rename owncloud to nextcloud (e.g. domains, datadirectory, database)
  • mv /srv/owncloud/ /srv/nextcloud
  • cp -ar ../owncloud_backup_`date -I`/data .
  • mysql nextcloud < ../owncloud_backup_`date -I`.sql
  • chmod u+x occ
  • sudo -u www-data ./occ --version
  • sudo -u www-data ./occ upgrade

cron job

  • crontab -u www-data -e
    • */15  *  *  *  * nice -n 19 ionice -c3 php -f /var/www/nextcloud/cron.php

Upgrade to subsequent Nextcloud versions

  • via Webtool
  • Login as admin
  • Go to admin settings page
  • Scroll to the version number, click update, follow instructions
  • Repeat until at latest version

cleanup

  • a2dissite owncloud
  • rm /etc/apache2/sites-available/owncloud.conf
  • service apache2 restart
  • certbot delete
  • mysql -e "DROP DATABASE owncloud;"
  • after a few days/weeks remove backups in /var/www