How to Sync the Nextcloud Calendar in a Subdirectory

Published by on

The other day I installed a Nextcloud instance on my web space.

My trust in the integrety of the providers free cloud services has been fading recently, so I decided to move as much data as possible from providers like Dropbox and Google to servers that I can control.

What's Nextcloud?

Nextcloud is a suite of client-server software for creating and using file hosting services. It is functionally similar to Dropbox, although Nextcloud is free and open-source, allowing anyone to install and operate it on a private server.

Even though Nextcloud is mostly known as a replacement for Dropbox, it is also possible to install a calendar plugin, making it a viable replacement for Google Calendar.

I'm using a shared hoster for my web site and installed my Nextcloud instance in a subdirectory, so I could access it under https://mycool.seite/services/nextcloud

Using Nextcloud's web installer worked flawlessly; Adding the calendar plugin was went smoothly as well.

Screenshot of the NextCloud calendar app with an open dialog for editing an event

A added a new sample event for testing

Setting Up Sync with the Mac Calendar App

While the user iterface of the Nextcloud calendar is functional and easy to use, I prefer to manage my calendars with native apps on macOS and Android.

CalDAV is a protocol that enables synchronisation of calendars across devices and apps. It is supported by both the Nextcloud calendar and the macOS Calendar app.

The Nextcloud calendar provides a CaldDAV endpoint which the macOS Calendar app can consume.

Screenshot of the NextCloud calendar app with the CalDAV settings highlighted

The CalDAV endpoint is located at the bottom left in the Nextcloud calendar.

In the macOS Calendar App, I created a new CalDAV account under Calendar > Accounts.

Screenshot of the MacOS internet accounts settings panel
Screenshot of the MacOS internet accounts settings panel with CalDAV option highlighted

By now sync should have worked, but there seemed to be some sort of problem with Nextcloud calendar's CalDAV URL:

Screenshot of a MacOS popup titled 'Add a CalDAV Account' with input fields for account type, email address and password

After some research I found the root of the problem: The macOS Calendar app is trying to request the following URLs in the root directory of the server:

  • .well-known/caldav
  • .well-known/carddav

This process is called Service Discovery and is described here in more detail: RFC5785.

Since my Nextcloud instance was installed in a subdirectory and not in the root directory, these requests return an error.

To fix the problem, I added a .htaccess file that in the root directory of my server that forwards these requests to my Nextcloud subdirectory.

Mein Hostinganbieter setzt (wie die meissten Anbieter von _Shared Hosting_) den Apache Webserver ein. Ich konnte deshalb relativ einfach eine Weiterleitung einrichten, indem ich eine .htaccess Datei im Hauptverzeichnis angelegt habe:

My hosting provider (like most _shared hosting_ providers) uses the Apache web server. So I was able to set up a redirection by creating an .htaccess file in the root directory:

After some research I found the root of the problem: The macOS Calendar app is trying to request the following URLs in the root directory of the server:

  • .well-known/caldav
  • .well-known/carddav

This process is called Service Discovery and is described here in more detail: RFC5785.

Since my Nextcloud instance was installed in a subdirectory and not in the root directory, these requests return an error.

To fix the problem, I added a .htaccess file that in the root directory of my server that forwards these requests to my Nextcloud subdirectory.

Mein Hostinganbieter setzt (wie die meissten Anbieter von _Shared Hosting_) den Apache Webserver ein. Ich konnte deshalb relativ einfach eine Weiterleitung einrichten, indem ich eine .htaccess Datei im Hauptverzeichnis angelegt habe:

My hosting provider (like most _shared hosting_ providers) uses the Apache web server. So I was able to set up a redirection by creating an .htaccess file in the root directory:

(if an .htaccess file already exists in this location, adding the redirect code at the end of the file should be sufficient.)

(if an .htaccess file already exists in this location, adding the redirect code at the end of the file should be sufficient.)

After adding these changes and saving the file, the synchrinisation via CalDAV worked and my events were synchronised:

Screenshot of the Mac Calendar App

The calendar was synchronised and is showing the event in the macOS calendar app.

Sync Nextcloud Calendar on Android

Unfortunately the Google Calendar app is not capable of syncing via CalDAV (at least with non-Google servers). So to get sync to work on my Android phone, I downloaded two free and open source Apps: DAVDroid and Etar.

DAVDroid enbles synchronisation via CalDAV, Etar is a great app to manage calendars.

After installing both apps, I set up DAVDroid to sync with my Nextcloud calendar. I selected (+) > Login with URL and user name and entered the CalDAV URL that the Nextcloud calendar provides:

Screenshot of an Android app for creating a CalDAV account

After setting up the account (the first sync may take a few seconds) I checked the calendar I wanted to synchronise:

Screenshot of an Android app for creating a CalDAV account

Once this was done, all my events were displayed correctly in Etar:

Screenshot of an Android calendar app

You can find more information on this topic here:

Leave a comment

Available formatting commands

Use Markdown commands or their HTML equivalents to add simple formatting to your comment:

Text markup
*italic*, **bold**, ~~strikethrough~~, `code` and <mark>marked text</mark>.
Lists
- Unordered item 1
- Unordered list item 2
1. Ordered list item 1
2. Ordered list item 2
Quotations
> Quoted text
Code blocks
```
// A simple code block
```
```php
// Some PHP code
phpinfo();
```
Links
[Link text](https://example.com)
Full URLs are automatically converted into links.

Replied on your own website? Send a Webmention!