Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Upgrade to Ubuntu 14.04.
Upgrade from Ubuntu 14.04 to Ubuntu 16.04
Migrate the server data to a supported version

Reason:
Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

Introduction

WebDAV is a distributed web authoring implementation built into HTTP that allows you to easily share files and work collaboratively with others.
We can install this extension within a web server to allow remote read and write access to local files through a web browser. In this guide, we will be configuring WebDAV on an Ubuntu 12.04 VPS with the Apache web server.

Install Apache on the VPS

Our implementation of WebDAV will be established on Apache through the use of the WebDAV module.
First, you will need to install Apache from Ubuntu’s default repositories.

sudo apt-get update
sudo apt-get install apache2

You now have a fully functioning web server installed. It should be accessible already by navigating to your server’s IP address in a web browser.

Enable WebDAV

Apache has built-in support for WebDAV with a few modules. We simply have to enable them to get access to their functions.
Enable the WebDAV modules with the following two commands:

sudo a2enmod dav
sudo a2enmod dav_fs

We now need to restart the server to implement the changes:

sudo service apache2 restart

WebDAV as a functionality is now enabled, but we still haven’t configured it correctly yet for our server.

Create the FileSystem

We will create a directory that will house our WebDAV file content.
The default document root of the Apache server on Ubuntu is located at /var/www. However, we will be creating an alias, which will allow us to keep our directory content elsewhere.
In this guide, we will place our WebDAV content at /webdav/

sudo mkdir /webdav

Give the web user, which is www-data, ownership of the new directory, so that it can serve content correctly:

sudo chown www-data /webdav

Set Up Password Protection

We can create an authentication procedure for accessing the directory content by creating an htpasswd file.
We will place it outside of the content directory so that it will not be accessible to users of our system. Create a username within the command call and you will be prompted for an associated password:

  
sudo htpasswd -c /etc/apache2/webdav.password username  

Right now, anybody can view the username and hashed password in the file. We will assign group ownership of the file to www-data and then lock down the permissions for everyone else:

sudo chown root:www-data /etc/apache2/webdav.password
sudo chmod 640 /etc/apache2/webdav.password

Configure Apache

Now, we will have to configure access to our content directory and tell Apache to use the WebDAV modules to serve that location. We will also have to note the authentication scheme we’ve created.
Edit the main virtual host configuration with root privileges:

sudo nano /etc/apache2/sites-available/default

Here, our web content is served out of /var/www like normal. We will add some information that will allow Apache to treat content in our new directory as WebDAV material.
Below the directory listings, we will add an alias directive to tell Apache that requests for “/webdav” should be served out of the /webdav directory we created.
We will then add options to allow authentication using the methods we established.

  
. . .  
. . .  
  
Options Indexes FollowSymLinks MultiViews  
AllowOverride None  
Order allow,deny  
allow from all  
  
Alias /webdav /webdav  
  
Options Indexes  
DAV On  
AuthType Basic  
AuthName “webdav”  
AuthUserFile /etc/apache2/webdav.password  
Require valid-user  
  
. . .  
. . .  

Save and close the file.
Restart Apache with the following command:

sudo service apache2 restart

Test the Results

You can test the results of you configuration first in a web browser, and then in a WebDAV client.

Web Browser Test

To test that your authentication is working correctly, navigate to your server’s IP address or domain name using a web browser.
You should see the default Apache index.html file:
<img style=“border:2px solid black; display:block;margin-left:auto;margin-right:auto” src=“https://assets.digitalocean.com/articles/webdav/default_apache.png” alt =“Apache Default index” />
This demonstrates that the regular web functionality is working.
Now, navigate to your IP address or domain name followed by “/webdav”:

  
your\_IP\_address\_or\_domain/webdav  

You should be prompted for the username and password combination you set up earlier. Afterwards, you should see an empty directory listing:
<img style=“border:2px solid black; display:block;margin-left:auto;margin-right:auto” src=“https://assets.digitalocean.com/articles/webdav/empty_webdav.png” alt =“Empty WebDAV” />
We don’t currently have any content here, but we’ll be able to change that by accessing the same area with a WebDAV client.

WebDEV Client Test

There are many WebDAV clients and support for WebDAV access is baked into many popular file managers.
For simplicity’s sake, we’ll use an easy command-line WebDAV client called “cadaver” in this guide.
Preferably from another droplet or Linux machine, install cadaver from the default repositories:

sudo apt-get install cadaver

Now, let’s create a file that we’ll upload to the WebDAV directory:

cd ~
touch testfile

Next, we’ll connect using the same location we used to access from the browser:

  
cadaver http://your\_IP\_address\_or\_domain/webdav  
  
Authentication required for webdav on server \`162.243.2.14’:  
Username:  

You must type the “http://” portion for cadaver to find your server correctly. We will need to authenticate again, and then we’ll be dropped into a command-line interface.

dav:/webdav/>

From here, we can operate the client and host at the same time using commands that are similar to regular Linux commands.
To list the contents of the server directory, type:

ls


Listing collection `/webdav/': collection is empty.

The directory is empty. Let’s change that uploading our test file:

put testfile

We can try the list command again and see the file is now on the server:

ls


Listing collection `/webdav/': succeeded.
        testfile                               0  Sep 20 19:36

We can make a directory and change into it by typing:

mkdir hello
cd hello

We can then create a file by typing:

edit file.html

We can insert whatever content we want:

<h1>Hi!!!</h1>

When we are finished, we can type exit to close the connection:

exit

Now, if we go back to our web browser, the changes that we’ve made are visible:

  
your\_IP\_address\_or\_domain/webdav  

<img style=“border:2px solid black; display:block;margin-left:auto;margin-right:auto” src=“https://assets.digitalocean.com/articles/webdav/webdav_content.png” alt =“WebDAV content” />

Turn Off Directory Listings

Although the directory listings are useful for seeing the files that WebDAV has available, it’s often useful, especially if you are using this for actual web content, to turn that listing off.
If you would like the web-accessible portion to act more like a website and less like a directory listing, remove the “Options Indexes” line from the configuration file:

sudo nano /etc/apache2/sites-available/default
  
Alias /webdav /webdav  
  
Options Indexes ## Remove this line  
DAV On  
AuthType Basic  
AuthName “webdav”  
AuthUserFile /etc/apache2/webdav.password  
Require valid-user  
  
. . .  
. . .  

Restart Apache to use your changes:

sudo service apache2 restart

Remember, you’ll need to create regular web pages for this to function correctly, like an “index.html” file:

sudo nano /webdav/index.html


<h1>Default WebDAV Page</h1>
<p>This is the default page with directory listings turned off</p>

Save and close the file.
This page will now appear when we’re navigating to the main WebDAV directory, but the edit functionality will still be enabled with clients.
<img style=“border:2px solid black; display:block;margin-left:auto;margin-right:auto” src=“https://assets.digitalocean.com/articles/webdav/webdav_landing.png” alt =“WebDAV landing page” />

Conclusion

You should now have a WebDAV directory complete with basic authentication. If your directory contains content that absolutely must be kept secure, you might want to implement an SSL solution on top of the password authentication. This, however, is outside of the scope of this article.
Many file managers and clients exist that can seamlessly access and modify WebDAV content as if it were additional local storage. WebDAV allows for a much more dynamic HTTP experience than is traditionally possible.

By Justin Ellingwood