Change Data Directory BEFORE or WHILE Installation to /media/

Hi folks, I hope you’re doing fine :slight_smile:
I just set up my Dell PowerEdge T20 with a fresh installation of Ubuntu Server 18.04 on my internal SSD. I also have an internal HDD, successfully mounted to /media/storage by editing /etc/fstab. Now I installed nextcloud via snap install nextcloud - but obviously it wont use the folder storage.

According to this article, subsequent changes to the data directory are not supported. Instead, re-installing Nextcloud with new data directory is recommended. I’d really like to do that - but if couldn’t find any information how I can change the (path to the) data directory before or while the installation via snap.

I’m very grateful for any kind of help :slight_smile:

if i understand the process to modify the path to data directory:

  • first you need to modify the /…/nextcloud/config/config.php 'datadirectory' => '/mnt/nextdata1/location1', to 'datadirectory' => '/mnt/nextdata1/location2', for exemple
  • And after that rescan the whole new datalocation sudo -u www-data php /path/to/nextcloud/occ files:scan --all

I beleive it the same process as adding files from an external storage

Hey, thank you for your fast reply!

This is how my config.php looks like - I have no line called datadirectory and if I understand the description correct, I don’t want to change the directory for the apps but for (my) data, which I’ll share over the network.

<?php

$snap_name = getenv('SNAP_NAME');

$CONFIG = array(
/**
 * Use the ``apps_paths`` parameter to set the location of the Apps directory,
 * which should be scanned for available apps, and where user-specific apps
 * should be installed from the Apps store. The ``path`` defines the absolute
 * file system path to the app folder. The key ``url`` defines the HTTP web path
 * to that folder, starting from the Nextcloud web root. The key ``writable``
 * indicates if a web server can write files to that folder.
 */
'apps_paths' => array(
        /**
         * These are the default apps shipped with Nextcloud. They are read-only.
         */
        array(
                'path'=> '/snap/'.$snap_name.'/current/htdocs/apps',
                'url' => '/apps',
                'writable' => false,
        ),

        /**
         * This directory is writable, meant for apps installed by the user.
         */
        array(
                'path'=> '/var/snap/'.$snap_name.'/current/nextcloud/extra-apps',
                'url' => '/extra-apps',
                'writable' => true,
        ),
),

/**
 * Database types that are supported for installation.
 *
 * Available:
 *      - sqlite (SQLite3 - Not in Enterprise Edition)
 *      - mysql (MySQL)
 *      - pgsql (PostgreSQL)
 *      - oci (Oracle - Enterprise Edition Only)
 */
'supportedDatabases' => array(
        'mysql',
),

'memcache.locking' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\Redis',
'redis' => array(
    'host' => getenv('REDIS_SOCKET'),
    'port' => 0,
),
);

Interestingly I initially had to login over webinterface for the first time, before the config.php had been automatically changed. But isn’t that more a “changing data directory after installation” way?

<?php
$CONFIG = array (
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/snap/nextcloud/current/htdocs/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/snap/nextcloud/current/nextcloud/extra-apps',
      'url' => '/extra-apps',
      'writable' => true,
    ),
  ),
  'supportedDatabases' =>
  array (
    0 => 'mysql',
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => '/tmp/sockets/redis.sock',
    'port' => 0,
  ),
  'instanceid' => 'nicetryxD',
  'passwordsalt' => 'nicetryxD',
  'secret' => 'nicetryxD',
  'trusted_domains' =>
  array (
    0 => '192.168.1.2',
  ),
  'datadirectory' => '/var/snap/nextcloud/common/nextcloud/data',
  'overwrite.cli.url' => 'http://192.168.1.2',
  'dbtype' => 'mysql',
  'version' => '13.0.5.2',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:/tmp/sockets/mysql.sock',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'nicetryxD',
  'installed' => true,
);

Unfortunately after changing the datadirectory and restarting the server, I get the following error message in the webbrowser:

Internal Server Error

    The server encountered an internal error and was unable to complete your request.
    Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
    More details can be found in the server log.

I didn’t do the thing which you called “rescan the whole new datalocation”, because I can’t use the occ command. As written here, the occ should be in the nextcloud/ directory. Unfortunately i can’t use the command - I tried all possible folders:

root@server-linux:/var/snap/nextcloud/8267/nextcloud# find / -iname nextcloud
/root/snap/nextcloud
/var/snap/nextcloud
/var/snap/nextcloud/8267/nextcloud
/var/snap/nextcloud/8267/mysql/nextcloud
/var/snap/nextcloud/common/nextcloud
/snap/nextcloud
/snap/nextcloud/8267/htdocs/apps/gallery/js/vendor/nextcloud
root@server-linux:/var/snap/nextcloud/8267/nextcloud# cd /root/snap/nextcloud
root@server-linux:~/snap/nextcloud# occ

Command 'occ' not found, but there are 21 similar ones.

root@server-linux:~/snap/nextcloud# cd /var/snap/nextcloud
root@server-linux:/var/snap/nextcloud# occ

Command 'occ' not found, but there are 21 similar ones.

root@server-linux:/var/snap/nextcloud# cd /var/snap/nextcloud/8267/nextcloud
root@server-linux:/var/snap/nextcloud/8267/nextcloud# occ

Command 'occ' not found, but there are 21 similar ones.

root@server-linux:/var/snap/nextcloud/8267/nextcloud# cd /snap/nextcloud
root@server-linux:/snap/nextcloud# occ

Command 'occ' not found, but there are 21 similar ones.

Not sure what is possible with the snap version, if occ command is blocked or available. It can be also used to do initial install with custom parameters, which is normally done interactively on first web ui access and creates the final config.php. But on snap this seems to work non-interactively?

You could try to add the datadirectory entry to the config.php prior to first web ui access. Perhaps it is respected then.

We also found that at l least since NC13, if you move the datadir to another location and change the config.php entry afterwards after initial setup, there is no manual database change needed anymore. But there is no official confirmation for this.