1. Install Dependencies (Debian Buster)
  2. Setup database
  3. Download and Install
  4. How to setup SSL cert (Let’s Encrypt)
  5. How to setup 2FA

Install Dependencies (Debian Buster)

# install core packages
apt-get install apache2 mariadb-server libapache2-mod-php
# install php modules
apt-get install php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip php-cli php-cgi

Setup database

# run the secure installation script to setup the root db account
sudo mysql_secure_installation

# sign into MariaDB using the root password
sudo mysql -u root -p

# create a new db

# create new user for the the nextcloud db
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'yourpassword';

# grant full privileges on the db for the new user
GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost';

# flush privileges and quit

Download and Install

# download Nextcloud archive

md5sum -c nextcloud-17.0.0.tar.bz2.md5 < nextcloud-17.0.0.tar.bz2

# extract the archive
tar -xjf nextcloud-x.y.z.tar.bz2

# copy the nextcloud directory to the http server root (if not already there)
cp -r nextcloud /var/www/html/

# give ownership of the nextcloud directory to www-data
sudo chown -R www-data:www-data /var/www/html/nextcloud

# that's it!
# nextcloud dashboard should be accessible at localhost/nextcloud
# if you need access to the UI from somewhere other than localhost, change the trusted domains section of config/config.php

How to setup SSL cert (Let’s Encrypt)

# tested under Debian Buster
# add repo
sudo add-apt-repository ppa:certbot/certbot
# install certbot
sudo apt install python-certbot-apache
# start interactive session to get certificate
sudo certbot --apache -d <yourdomain>

How to setup 2FA

TOTP app on Nextcloud

cd ./nextcloud/apps/
# download the TOPT app (direct link)
# unzip the archive , it will unzip a single appropriate folder
tar -xzf twofactor_totp.tar.gz
# now the app should be listed in your app dashboard and you can enable it

References and more: