Running Baikal DAV server on a RunCloud VPS
A proper tech post…
If, like me, you need to keep a calendar and contacts synced between computer (M1 Mac) and phone (Android), have a limited budget, but are not willing to sell your soul or your data to a tech giant in order to do so, your options are limited. Apple iCloud? No. Microsoft Outlook? Nope. Google? Absofuckinglutely not. Zoho? No, I don’t trust them either.
Away from the giants, the best known third party option is Fruux, and I used it for quite some time, but increasingly it throws errors when Apple Calendar tries to sync, and its web interface displays HTTP 500 errors more often than real pages.
Some web hosting companies also offer CalDAV and CardDAV hosting if you use their services, but none of these companies are ones that I would actually trust to keep my data safe and help me if there was a problem (Ionos? Do me a favour…).
Now you’re talking.
There are a few possible contenders:
- OwnCloud – PHP-based groupware, focus is on corporate solutions but self-hosting available
- NextCloud – Fork of OwnCloud by the original creator, widely used
- Radicale – Python-based pure CalDAV and CardDAV server (much narrower focus than NextCloud)
- Baikal (styled as Baïkal for some reason) – PHP-based pure CalDAV and CardDAV server
There may be more but these were the ones I found.
Because I’m a PHP expert with no real experience of Python, that put Radicale out of the running for me. And after reading many comparisons of OwnCloud and NextCloud, it was clear that NextCloud attracts many more self-hosters than OwnCloud.
So, NextCloud or Baikal? One is a complete groupware environment, the other a small, lightweight, focussed solution.
Well, I tried both. Duh.
In fact, and here is a small diversion in the interests of completeness, I tried them both about 2 years ago, and failed to get either one working reliably, which is why I ended up using Fruux for ages.
In NextCloud’s case, I got it installed successfully (I believe I was using Cloudways hosting at the time), but I wanted to make proper use of the groupware features such as file storage, and I couldn’t make it accept any file uploads larger than about 10Mb. No way, no how. Looking back now, I guess it would have been related to this issue, but at the time I couldn’t get NextCloud support to take me seriously. So my assessment of NextCloud was “fuck this for a game of soldiers”.
Then I tried Baikal, but couldn’t get either Apple Calendar or Thunderbird’s Lightning to connect and sync. Since I think this was in 2020, I would have been using Baikal 0.5.x, though I can’t recall precisely.
I figured the “0.” in front of the version meant that Baikal simply wasn’t ready for primetime, and didn’t pursue it further. I found Fruux, which was free for up to 2 devices, so for a while that was OK.
Now, fast forward to 2022, and both Thunderbird and Apple Calendar keep failing to connect to Fruux. Also, as noted above, logging in to Fruux to check if events are getting through often results in HTTP 500 error pages.
So the inevitable thought that crossed my mind (well, inevitable if you’re me) was, “hmm, I wonder if Baikal is better now?”
Setting up Baikal
These days I manage a set of bare-metal VPS servers with RunCloud, which means I have far greater control over everything than when I used Cloudways. I decided that Baikal had to be worth one more try.
So, here are the steps I followed:
- Set up a subdomain to use for Baikal (you know, like dav.mydomain.com).
- Created a new system user in RunCloud.
- Created a new empty hybrid webapp (Nginx + Apache) in RunCloud, controlled by the above system user, and added a Let’s Encrypt certificate.
- Created a new database + user in RunCloud.
- Downloaded and unzipped Baikal 0.9.2.
- Read the installation instructions.
- Uploaded the Baikal install files to the webspace, and set the application root to point to the html folder in the RunCloud console.
- Ran the installer in my browser, choosing the MySQL database option.
- Set up a user account in Baikal and tried to connect from my Mac. No joy.
Damn, I thought.
Then I read the installation instructions again, particularly the Nginx Configuration section.
What I had thought was unnecessary code (because RunCloud sets up the virtual host automatically) actually contained a couple of lines that were related specifically to a DAV setup:
rewrite ^/.well-known/caldav /dav.php redirect;
rewrite ^/.well-known/carddav /dav.php redirect;
So I added these two lines to a fresh custom Nginx config file in my RunCloud console. I selected the “location.main-before” priority and called the file “wellknown.conf”.
The Accounts app in Apple System Preferences instantly connected to Baikal – both CalDAV and CardDAV. Note that I used just the basic subdomain name as the server name when connecting (like dav.mydomain.com, no https, no slashes, no path, nothing else).
So I imported my calendar and contacts files and could see the event and contact counts gradually increasing in the Baikal admin console.
Next, I used DAVx5 on my Android phone to connect, which it did without problems.
A simple, satisfactory solution
So, I now have a private online calendar and contacts address book, hosted using open source software on a server that I pay for anyway, and accessible by as many devices as I choose. I can back it up whenever I like, either via exporting in macOS or a complete FTP backup and database dump, and I can restrict access to specific IP addresses in RunCloud if I choose.