Deploy Nextcloud with Object Storage

Reviewed on 17 November 2021Published on 16 November 2018
  • storage
  • object-storage
  • Nextcloud
  • cloud
  • selfhosted

Nextcloud Overview

Nextcloud is an open source, self-hosted file share and communication platform.

Combining Nextcloud with Object Storage gives you infinite storage space for your personal cloud.

Requirements:

Installing Nextcloud

  1. Log in to your server via SSH.

  2. Update the apt-sources and the already installed software on the server:

    apt update && apt upgrade -y
  3. Install the required software from the apt repositories:

    apt install apache2 mariadb-server libapache2-mod-php7.4
    apt install php7.4-gd php7.4-json php7.4-mysql php7.4-curl php7.4-mbstring php7.4-intl php-imagick php7.4-xml php7.4-zip
  4. Download the lastest version of Nextcloud:

    wget https://download.nextcloud.com/server/releases/latest.tar.bz2
    Tip:

    Check the Nextcloud changelog for the latest release.

  5. Extract the archive:

    tar -xjf latest.tar.bz2
  6. Copy the Nextcloud directory to the document root of Apache:

    cp -r nextcloud /var/www
  7. Create a Apache configuration file for Nextcloud:

    nano /etc/apache2/sites-available/nextcloud.conf

    And put the following content into it:

    Alias /nextcloud "/var/www/nextcloud/"

    <Directory /var/www/nextcloud/>
    Options +FollowSymlinks
    AllowOverride All

    <IfModule mod_dav.c>
    Dav off
    </IfModule>

    SetEnv HOME /var/www/nextcloud
    SetEnv HTTP_HOME /var/www/nextcloud

    </Directory>
  8. Enable the configuration and reload Apache to activate the site:

    a2ensite nextcloud.conf
    systemctl reload apache2
  9. Enable SSL. Apache provides a self-signed certificate to encrypt the connection to your server. You can activate it with the following commands:

    a2enmod ssl
    a2ensite default-ssl
    systemctl reload apache2
    Tip:

    A self signed certificate may have some drawbacks if you want to make your Nextcloud installation publicly available, a warning may appear in the browser. If required, you can request a free signed certificate from Let’s Encrypt.

  10. Set the file permissions to the Apache user:

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

Configuring MariaDB

Important:

It is required thet you have configured your MariaDB server before you run these commands.

  1. Connect to the MariaDB server:

    mysql -u root -p
  2. Create an empty database for Nextcloud:

    CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'password';
    CREATE DATABASE IF NOT EXISTS nextcloud;
    GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'password';
    FLUSH privileges;
  3. Log out from the MariaDB shell:

    EXIT;

Completing the setup wizard

  1. Run the installation wizzard by opening your web browser and accessing Nextcloud at https://YOUR_SERVER_IP/nextcloud Remember to replace YOUR_SERVER_IP with the IP address of your server.

  2. Fill out the setup form with the credentials for the admin user and the database settings that you have configured in the previous step.

Configuring Object Storage as primary storage in Nextcloud

Nextcloud can use Object Storage as primary storage. This gives you the possibility to store infinite data in your personal cloud.

Important:

Configuring Object Storage as primary storage on an existing Nextcloud instance will make all existing files on the instance inaccessible. It is therefore recommended to configure Object Storage on a fresh installation.

  1. Retrieve your ACCESS-KEY and SECRET-KEY from the Scaleway console.

  2. Open the Nextcloud configuration file in a text editor (i.e. nano):

    nano /var/www/nextcloud/config/config.php
  3. Add a configuration block for S3 compatible storage as follows:

    'objectstore' => array(
    'class' => '\\OC\\Files\\ObjectStore\\S3',
    'arguments' => array(
    'bucket' => 'my-nextcloud-storage-bucket',
    'autocreate' => true,
    'key' => 'ACCESS-KEY',
    'secret' => 'SECRET-KEY',
    'hostname' => 's3.fr-par.scw.cloud',
    // The hostname depends on the geographical location of your bucket: It can be either s3.fr-par.scw.cloud, s3.nl-ams.scw.cloud or s3.pl-waw.scw.cloud
    'port' => 443,
    'use_ssl' => true,
    'region' => 'fr-par',
    // Region can be either fr-par, nl-ams, or pl-waw
    ),
    ),

    The configuration file should look like the following example after modification:

    <?php
    $CONFIG = array (
    'instanceid' => 'instanceid',
    'passwordsalt' => 'hashedpassword',
    'secret' => 'secret',
    'trusted_domains' =>
    array (
    0 => 'YOUR-NEXTCLOUD-HOSTNAME',
    ),
    'objectstore' => array(
    'class' => '\\OC\\Files\\ObjectStore\\S3',
    'arguments' => array(
    'bucket' => 'my-nextcloud-storage-bucket',
    'autocreate' => true,
    'key' => 'ACCESS-KEY',
    'secret' => 'SECRET-KEY',
    'hostname' => 's3.fr-par.scw.cloud',
    'port' => 443,
    'use_ssl' => true,
    'region' => 'fr-par',
    ),
    ),
    'dbtype' => 'mysql',
    'version' => '16.0.3.0',
    'overwrite.cli.url' => 'https://YOUR_NEXTCLOUD_HOSTNAME/nextcloud',
    'dbname' => 'nextcloud',
    'dbhost' => 'localhost',
    'dbport' => '',
    'dbtableprefix' => 'oc_',
    'dbuser' => 'nextcloud',
    'dbpassword' => 'databasepassword',
    'installed' => true,
    );
  4. Save the configuration file, close the text editor and open the Nextcloud web interface in a browser. Nextcloud uses Object Storage for storing files now:

Note:

Accessing the web interface for the first time may take a moment, as Nextcloud configures the bucket in the background before displaying the interface.

Configuring Object Storage as external storage in Nextcloud

You can use Nextcloud as a client for Object Storage while using the local storage as primary storage. This can be useful for a migration of an existing Nextcloud instance to Object Storage.

  1. Log into your Nextcloud to configure the Object Storage bucket.

  2. From the Nextcloud interface, click Apps in the drop-down menu to access the list of available apps:

  3. Enable the External Storage Service by clicking on Enable:

  4. Click Settings in the drop-down menu, then on External Storages in the Administration section of the page:

  5. Configure the credentials for your bucket:

    - `Bucket` = The Name of your bucket
    - `Hostname` = The hostname of the bucket (For Scaleway Object Storage in Amsterdam: `s3.nl-ams.scw.cloud`, for Scaleway Object Storage in Paris: `s3.fr-par.scw.cloud` for Warsaw: `s3.pl-waw.scw.cloud`)
    - `Port` = The port for your bucket, leave this empty
    - `Region` = The geographical region of your bucket (Either: `nl-ams` for Amsterdam, The Netherlands, `pl-waw` for Warsaw, Poland or `fr-par` for Paris, France)
    - `Enable SSL` = Activate this checkbox to encrypt the connection between your Nextcloud and the Bucket
    - `Access Key` = Your [Access Key](/console/my-project/how-to/create-ssh-key/)
    - `Secret Key` = Your [Secret Key](/console/my-project/how-to/create-ssh-key/)

    Once you have entered all details, click the checkmark to validate your configuration. If everything works well, a green dot will appear on the left.
  6. Click the file icon, then on External Storages to access your bucket:

You can now upload and manage the files in your bucket directly from Nextcloud.