March 21, 2019

Easy Linux Fileserver With WebDav

WebDAV and Apache2

  • March 8, 2011
  • By Juliet Kemp
You don't need some big fancy expensive groupware suite for simple file sharing; just set up a good stout Linux server with WebDav and be done with it. No muss, no fuss.

Juliet Kemp

The WebDAV protocol allows you to store and share files via HTTP; effectively, where HTTP is usually read-only, WebDAV allows writing as well. As well as accessing documents, you can (with suitable permissions) edit and re-upload them. You can think of it as a networked file-system run over HTTP; or as a way of supporting long-distance collaboration on files. The protocol supports locking and versioning information, so once you've accessed the WebDAV folder (see below), you can edit files without risking overwriting other people's edits. These days there are more and more ways available to undertake online collaboration, but WebDAV is still a useful and straightforward way to share files, especially as it's supported by plenty of software at both server and client end.

Unlike FTP, HTTP provides strong authentication and encryption, as well as caching and proxy support – and because WebDAV works over HTTP, this means that WebDAV gets all of that for free. SSH would be another option, but SSH is a bit more limited in terms of moving files around, and certainly doesn't have the same sort of client support and tools available.

WebDAV and Apache2

It's straightforward to get an Apache server to serve up a WebDAV folder. The Apache module you want is mod_dav. To enable this on a Debian/Ubuntu system, just type:

a2enmod dav
a2enmod dav_fs
/etc/init.d/apache2 restart
mod_dav provides the server with the WebDAV functionality (i.e. it implements the relevant HTTP protocol extensions), and mod_dav_fs supports it, allowing access to resources in the server's filesystem. Further detailed information on the dav and dav_fs modules is available from the Apache webpage.

You'll also need to set up specific folders to access via WebDAV. Here's an example:

    Dav On

    Order Allow,Deny
    Allow from all

    AuthType Digest
    AuthName WebDAV-Realm

    AuthUserFile "/usr/var/webdav.passwd"

    require user juliet
The most important line here is Dav On, which turns this directory into a WebDAV one. The rest is about securing access to the directory. It's important to make sure that you have authentication set up before you enable WebDAV on any directories, or you'll have a big security hole. The config here uses MD5 Digest authentication (recommended over htaccess for security), and would limit all access to the named user. You could also use just require valid-user; or you can make your setup as complicated as MD5 Digest allows.

Note that to allow writing to (as well as reading from) your directory, you'll need to change the permissions on that directory appropriately. In particular, you need the directory to be writeable by the Apache user. Again, note the security issues here! It's a good idea to keep your WebDAV directory reasonably separate from the rest of your website files.

To set WebDAV up manually, you'll need to have the following somewhere in your Apache conf file:

LoadModule dav_module /usr/lib/apache2/modules/mod_dav.so
LoadModule dav_fs_module /usr/lib/apache2/modules/mod_dav_fs.so
Then restart Apache, and set up the directory you want to use as above.

Most Popular LinuxPlanet Stories