Nextcloud Snap Installation

The Nextcloud installation page has two sets of instructions now: automatic and manual. Previously on this website, I have described the manual steps to setting up Nextcloud. It is a good learning experience and worth a try, but even better is the automatic installation using snaps.

“Snaps are containerised software packages that are simple to create and install. They auto-update and are safe to run. And because they bundle their dependencies, they work on all major Linux systems without modification.” [source]

Now, the steps are almost one step:

sudo snap install nextcloud

Reaching via different host names

By default, the only allowed hostname is “localhost”.If you are accessing your server by another name (e.g. 192.168.1.8 or nextcloud-server.com), you need to add the trusted domains.

If you access the server on your Nextcloud server machine, the website will prompt you to add the trusted domains.

Otherwise for a quicker setup, you can add your trusted domains via the command line.

sudo nextcloud.occ config:system:set trusted_domains 1 --value=192.168.1.8
sudo nextcloud.occ config:system:set trusted_domains 2 --value=nextcloud-server.com
sudo nextcloud.occ config:system:set trusted_domains 3 --value=www.nextcloud-server.com

Verify the results:

cat /var/snap/nextcloud/current/nextcloud/config/config.php

Results

array (
   0 => 'localhost',
   1 => '192.168.1.8',
   2 => 'nextcloud-server.com',
   3 => 'www.nextcloud-server.com',
),

External Hard Drive

In order to point your Nextcloud’s data directory to an external hard drive, follow these steps, assuming your external hard drive and new Nextcloud data directory is located at:

/media/<user>/<hard_drive_name>/nextcloud_data_directory

Log into your server first and set up an admin account.

Make sure your Nextcloud server is enabled.

sudo snap enable nextcloud

Connect the remove-media snap plug so that the Nextcloud server can access your external hard drive.

sudo snap connect nextcloud:removable-media

Change the Nextcloud server’s config file to point to the new data directory, so do

vi /var/snap/nextcloud/current/nextcloud/config/config.php

And change  the value of “datadirectory” to

'datadirectory' => '/media/<user>/<hard_drive_name>/nextcloud_data_directory',

Now, disable the Nextcloud server.

sudo snap disable nextcloud

And move all the data to the new data folder (including hidden files!)

sudo mv /var/snap/nextcloud/common/nextcloud/data/* /media/<user>/<hard_drive_name>/nextcloud_data_directory
sudo mv /var/snap/nextcloud/common/nextcloud/data/.* /media/<user>/<hard_drive_name>/nextcloud_data_directory

Set the proper permissions so your Nextcloud server can access the hard drive and not complain:

sudo chown -R root:root /media/<user>/<hard_drive_name>/nextcloud_data_directory
sudo chmod -R 0770 /media/<user>/<hard_drive_name>/nextcloud_data_directory

Re-enable your Nextcloud server

sudo snap enable nextcloud

Enabling HTTPS

Before using snap, verify that your domain name directs to your server. Then, use this simple snap command that will generate a Let’s Encrypt SSL certificate automatically.

sudo nextcloud.enable-https lets-encrypt

Other

If you cannot access the files after moving to the external hard drive, you might consider reading about dropping your mysql data tables. [link]

If you want to keep your nextcloud.log file on your local disk, because it will move by default with your data directory. [link]

References

This entry was posted in How-To, Nextcloud/OwnCloud and tagged , , , , , , , . Bookmark the permalink.

3 Responses to Nextcloud Snap Installation

  1. enekofer says:

    Hi Brian!
    Thank you for sharing this guide to setup nextlcoud snap on an external hdd.

    I have a problem in this point:
    And move all the data to the new data folder (including hidden files!)

    sudo mv /var/snap/nextcloud/common/nextcloud/data/* /media///nextcloud_data_directory
    sudo mv /var/snap/nextcloud/common/nextcloud/data/.* /media///nextcloud_data_directory

    It throws me the next:mv: cannot stat error : No such file or directory error

    What’s happening? Do yo kwno how to fix it?

    Regards

  2. Trip Hazzard says:

    Hi! Thanks for this great article. I was wondering, is there a way to configure the mysql server that comes with the Snap version of Nextcloud to enable replication? I know the maintainer specificially mentions this as something that would likely mean a manual install using .deb packages/apt would be better, but Snaps should hopefully make updating a little cleaner. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s