HOWTO
FILESYSTEM
WEBDAV ON APACHE

Published: 20201003

Tested on:
* Ubuntu Server 20.04.1 on a VMware VM.
* Ubuntu for IoT 20.04.1 arm64 was tested on a RPi 4B 4G.

-

Just small notes on how to install WebDAV on Apache 2.4.
If you wonder what WebDAV is... It's like a samba share but from a webserver.

INDEX
01. Requirements
02. Installing the WebDAV server
03. Mounting a WebDAV filesystem on Linux
04. Mounting a WebDAV filesystem on Windows 10
05. Other ways of using WebDAV

-

  1. Requirements

    If you want all of this to be encrypted, you have to do this on https.
    This HOWTO assumes you know how to setup https on Apache.
    It also assumes you have setup an Apache Virtual Host called test.example.com.

  1. Installing the WebDAV server

    Create a dir for your webdav share:

    $ sudo mkdir -p /home/webdav/share1
    $ sudo chown www-data /home/webdav/share1
    $ sudo chgrp www-data /home/webdav/share1
    $ sudo chmod 0700 /home/webdav/share1
    

    If you choose another user for the dir, you need to make sure that the apache service can both read and write to this dir.

    Edit your virtual host configuration:

    $ sudo vi /etc/apache2/sites-available/test.example.com-ssl.conf
    

    Add the lines between the two comments:

    <VirtualHost *:443>
      ServerAdmin   webmaster@example.com
      DocumentRoot  /home/wwws/test.example.com
      ServerName    test.example.com
         
      SSLEngine on
      SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
      SSLCertificateFile      /etc/letsencrypt/live/test.example.com/cert.pem
      SSLCertificateKeyFile   /etc/letsencrypt/live/test.example.com/privkey.pem
      SSLCACertificateFile    /etc/letsencrypt/live/test.example.com/fullchain.pem
         
      CustomLog     /var/log/apache2/test.example.com-ssl-access.log combined
      ErrorLog      /var/log/apache2/test.example.com-ssl-error.log
      <Directory    /home/wwws/test.example.com>
        AllowOverride all
        Require all granted
      </Directory>
         
      # WebDAV configuration starts here
      Alias /webdav-share1 /home/webdav/share1
      <Location /webdav-share1>
        DAV on
        SSLRequireSSL
        Options None
        AuthType Basic
        AuthName WebDAV
        AuthUserFile /home/webdav/share1-htpasswd
        <RequireAny>
          Require method GET POST OPTIONS
          Require valid-user
        </RequireAny>
      </Location>
      # WebDAV configuration ends here
         
    </VirtualHost>
    

    Create the htpasswd file by adding its first user:

    $ sudo htpasswd -c /home/webdav/share1-htpasswd alice
    New password:
    Re-type new password:
    Adding password for user alice
    $ 
    

    Activate the WebDAV Apache modules:

    $ sudo a2enmod dav*
    Enabling module dav.
    Considering dependency dav for dav_fs:
    Module dav already enabled
    Enabling module dav_fs.
    Enabling module dav_lock.
    To activate the new configuration, you need to run:
      systemctl restart apache2
    $ sudo systemctl restart apache2
    $ 
    

    Done!

  1. Mounting a WebDAV filesystem on Linux

    You need to specify which user will "own" the mounted dir.
    If you don't know your UID and GID you can use this command:

    $ id
    uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu)
    $ 
    

    How to mount WebDAV:

    $ sudo apt install davfs2
    $ sudo mkdir /mnt/webdav-dir1
    $ sudo mount -t davfs -o uid=1000,gid=1000 https://test.example.com/weddav-share1 /mnt/webdav-dir1
    Please enter the username to authenticate with server
    https://test.example.com/webdav-share1 or hit enter for none.
      Username: alice
    Please enter the password to authenticate user alice with server
    https://test.example.com/webdav-share1 or hit enter for none.
      Password:
    $ 
    

    How to unmount:

    $ sudo umount /mnt/webdav-dir1
    

    WARNING For some odd reason, Ubuntu 20.04 can't unmount WebDAV, the process segfaults. Basically you need to restart your machine to unmount. The bug is tracked here.

    It works fine on Raspberry Pi OS, so the bug is Ubuntu specific. (Maybe even just Ubuntu 20.04 specific.)

  1. Mounting a WebDAV filesystem on Windows 10

    Your WebDAV share is now usable.

    Next time you boot Windows 10, the share name will be visible, but it will not be usable. This is due to how Windows establishes WebDAV connections. You have to delete the share and mount it again, or use some kind of WebDAV client. If you saved the credentials, at least you wont have to enter them again.

    If you stored the credentials and need to delete them, then search (in the Windows 10 search bar) for "Manage Windows Credentials". Here you can delete the stored credentials. After that you need to reboot Windows for the changes to take effect. Because... Windows.

  1. Other ways of using WebDAV

    I've successfully tested this WebDAV setup with:

    It likely work with a thousand apps more, but I think you get the idea...
    You can replace "cloud storage" with hosting your online data yourself.