How to install webDAV under Apache on Ubuntu (16.04)

HOW-TO DISCLAIMER: Most of the “how-to” posts are copy/pasted from a personal notes blog I keep for myself and as such sometimes presume familiarity with some of the concepts that might not be obvious. I’d like to make my notes and how-to’s more informative and accessible to a wider audience, so please let me know if something is not clear (or just plain wrong).

Enabling modules

The first thing you must do is enable the necessary modules. Open a terminal window and issue the following commands:

sudo a2enmod dav
sudo a2enmod dav_fs

Restart the Apache server with this command:

sudo systemctl restart apache2

Virtual host configuration

The next step is to create everything necessary for the virtual host. This will require creating specific directories (with specific permissions) and editing an Apache .conf file.

Let’s create the necessary directories. For simplicity, I’ll create a folder called webdav. From the terminal window, issue this command:

sudo mkdir -p /var/www/html/dav

Now we’ll change the owner of that directory to www-data with this command:

sudo chown www-data /var/www/html/dav

The next step is to create a .conf file that will help make apache aware of the virtual host. For this, we’ll create a new .conf file called /etc/apache2/sites-available/webdav.conf. The contents of this file will be:

<VirtualHost *:80>

ServerAdmin chuck@planethawleywood.com
ServerName webdav.planethawleywood.com
DocumentRoot /var/www/html/dav/

<Directory /var/www/html/dav/>
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    DAV On
    AuthType Basic
    AuthName "webdav"
    AuthUserFile /var/www/html/dav/passwd.dav
    Require valid-user
</Directory>

</VirtualHost>

Save and close the file.

Now we enable the webdav.conf file with:

sudo a2ensite webdav.conf

Before restarting apache, we need to create the WebDAV password file with this command (USER is a valid username on your system):

sudo htpasswd -c /var/www/html/dav/passwd.dav <user>

NOTE: if you need to update or recreate the users webDAV password, run the same command with out the -c option. (-c creates a new entry)

When prompted enter the password for USER.

Next we must change the permissions of the newly created passwd.dav file so that only root and members of the www-data group have access to it. You’ll do so with the following commands:

sudo chown root:www-data /var/www/html/dav/passwd.dav
sudo chmod 640 /var/www/html/dav/passwd.dav

Restart apache with this command:

sudo systemctl restart apache2

The WebDAV system is ready to test.

Testing your setup

There’s an easy to use tool for testing WebDAV—install the tool with this command:

sudo apt-get install cadaver

Once installed, issue this command (IP_OF_SERVER is the actual IP address of your server):

cadaver http://<server-name>

You should be prompted for a username/password. Enter the USER used when setting up WebDAV and the associated password. If the cadaver command succeeds, you’ll land at the dav:/webdav/> prompt. Type exit to exit cadaver.

Congratulations, WebDAV is working on your Ubuntu server. You can now use whatever tool you need (connect via file managers, web browsers, etc.) to connect to your WebDAV server.


Reference