Run your own webdav sync with SabreDAV

I thought I’d share how to run a simple PHP webdav server using SabreDAV for syncing DEVONthink databases. Because it’s yours, it’s fast, private and secure. If you already have some PHP hosting, it’s free!

Here’s how to do it.

The sync app

I’m using SabreDAV. Here’s the entire app:

data and files are empty directories. Files will hold all your sync data, and data is used during sync.

This is a PHP app, so composer installs packages. The only composer command you need is composer require sabre/dav

Here’s index.php. This is the only coding bit. You can just copy this if your app folders look like mine.

use Sabre\DAV;
use Sabre\DAV\Auth;
use Sabre\DAVACL;

require '../vendor/autoload.php';

$rootDir = new DAV\FS\Directory('../files');

$server = new DAV\Server($rootDir);

$lockBackend = new DAV\Locks\Backend\File('../data/locks');
$lockPlugin = new DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);

$server->addPlugin(new DAV\Browser\Plugin());

$authBackend = new Auth\Backend\File('../.htdigest');
$authBackend->setRealm('SabreDAV');
$authPlugin = new Auth\Plugin($authBackend);
$server->addPlugin($authPlugin);

$server->exec();

Here’s the one line .htdigest file. I have all my DT instances using this login, but you can add as many lines as you want. You can generate these lines with an htdigest generator.

username:SabreDAV:43b3fbe6b608be6e0ef19b3b2ed0fake

This protects your files from web access; it’s also your sync credentials.

Deploying

There are lots of ways to host/deploy this. You just need to run PHP. I’m using Ploi to manage an existing Linode server on a new subdomain I made for webdav. You can run this fine on a cheap $5 server, but you’ll need enough storage space for your data. My existing Linode server had about 30GB free, which is plenty. The deploys are just checkout from main, composer install, restart PHP (ploi sets up a default script for this.)

If you can’t use a server manager or composer, you can download and use the source code from SabreDAV’s releases on GitHub. Then you just deploy by pushing up the whole folder.

If you’re using my folder structure, you want the app’s public folder to be root directory of the subdomain so you can visit webdav.example.com to make sure webdav is working. You do this because it prevents everything else from being directly browsable.

Updating

Honestly, you don’t need to update the code unless some awful vulnerability is found, because you won’t be doing further development. Your app and files are completely inaccessible without the password in .htdigest. Security issues from the Sabre projects are rare, anyway.

DEVONthink setup

In Preferences > Sync, enable WebDAV. Settings:

  • URL: webdav.example.com
  • User Name and Password are what you used to make your .htdigest file
  • Sync Store Name: doesn’t matter
  • Encryption: anything you want. Typing something here prevents anyone reading your data on your server. Highly recommended
  • Check all the options

Why not use the Apache server that comes with macOS?

https://discussions.apple.com/docs/DOC-250007792

No need to install additional packages, no need for clumsy PHP, and it’s a proven implementation.

1 Like

This isn’t a guide for people doing that. (I knew I should’ve added disclaimers…) This is for people who want something accessible from the web, don’t want to punch holes in their home network and don’t want to pay for Dropbox or a dedicated sync service, essentially.