How to install Nextcloud?

Update: I recently launched a managed Nextcloud service provider with very competitive pricing for storage. If you’re planning to set up your own Nextcloud instance but have trouble finding a hosting provider with good pricing/storage ratio, please do consider signing up with us. There’s a free tier with 5GB storage so you can give the service a spin before deciding whether to upgrade the storage.

Nextcloud is the selfhosted’s community darling and probably needs no introduction. If you are a less discerning open-source tinkerer, you’d likely think that all commercial software can be replaced with Nextcloud or one of its apps.

Nextcloud can actually be installed with a click when you install a fresh copy of Ubuntu with snap but where’s the fun in that?

The following tutorial will teach you how to install Nextcloud from scratch on Debian:

  1. Update your package list

    sudo apt update

  2. Install the required packages

    sudo apt install nginx mariadb-server php-fpm php-mysql php-xml php-cli php-cgi php-mysql php-mbstring php-gd php-curl php-zip wget unzip ufw python3-acme python3-certbot python3-mock python3-openssl python3-pkg-resources python3-pyparsing python3-zope.interface python3-certbot-nginx -y

  3. Configure and run MySQL

    sudo mysql_secure_installation
    sudo mariadb

  4. Create the database (change the values below accordingly)

    CREATE DATABASE nextcloud;
    GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'nextclouduserpassword' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    exit

  5. Download Nextcloud (check the latest version and replace the value below accordingly)

    cd ~
    wget https://download.nextcloud.com/server/releases/nextcloud-20.0.4.zip
    unzip nextcloud-20.0.4.zip
    sudo mkdir /var/www/nextcloud && sudo mv nextcloud /var/www/nextcloud/
    sudo chown -R www-data:www-data /var/www/nextcloud/ && sudo chmod -R 755 /var/www/nextcloud/

  6. Create the Nginx configuration file for Nextcloud:

    sudo nano /etc/nginx/sites-available/nextcloud
    sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl reload nginx

  7. Secure NextCloud with Let’s Encrypt Free SSL

    sudo ufw allow 'Nginx Full'
    sudo certbot --nginx -d cloud.example.com

  8. That’s it. You can now visit your configured domain to complete the Nextcloud installation and get started.
  9. At this point, I highly recommend one to check out occ. Note that you’ll have to run the command in the Nextcloud installation directory itself (sample commands below):

    cd /var/www/nextcloud
    sudo -u www-data php occ -h
    sudo -u www-data php occ -V
    sudo -u www-data php occ app:install groupquota

  10. If you ever need to change the Nextcloud installation URL, just update the settings for trusted_domains and overwrite.cli.url in the following file:

    /var/www/nextcloud/config/config.php

2020-12-24

index