Tutorial

How To Configure WebDAV Access with Apache on Ubuntu 12.04

Published on September 20, 2013
How To Configure WebDAV Access with Apache on Ubuntu 12.04
Not using Ubuntu 12.04?Choose a different version or distribution.
Ubuntu 12.04

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:

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:

<pre> sudo htpasswd -c /etc/apache2/webdav.password <span class=“highlight”>username</span> </pre>

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.

<pre> . . . . . . <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory>

<span class=“highlight”>Alias /webdav /webdav</span>

<span class=“highlight”><Location /webdav></span> <span class=“highlight”>Options Indexes</span> <span class=“highlight”>DAV On</span> <span class=“highlight”>AuthType Basic</span> <span class=“highlight”>AuthName “webdav”</span> <span class=“highlight”>AuthUserFile /etc/apache2/webdav.password</span> <span class=“highlight”>Require valid-user</span> <span class=“highlight”></Location></span> . . . . . . </pre>

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”:

<pre> <span class=“highlight”>your_IP_address_or_domain</span>/webdav </pre>

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:

<pre> cadaver http://<span class=“highlight”>your_IP_address_or_domain</span>/webdav </pre> <pre> Authentication required for webdav on server `162.243.2.14’: Username: </pre>

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:

<pre> <span class=“highlight”>your_IP_address_or_domain</span>/webdav </pre>

<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 “<span class=“highlight”>Options Indexes</span>” line from the configuration file:

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

<pre>

Alias /webdav /webdav

<Location /webdav> <span class=“highlight”>Options Indexes ## Remove this line</span> DAV On AuthType Basic AuthName “webdav” AuthUserFile /etc/apache2/webdav.password Require valid-user </Location> . . . . . . </pre>

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.

<div class=“author”>By Justin Ellingwood</div>

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
8 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

I Appreciate it. Really helps me! \o/

thx you!!! all work perfect! ^________^

I’m still confused about this step "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/>" could you explain for me again? thanks

Hi, After prompting for user name and password, the browser showing ‘500: Internal Server Error’. Though all the commands and test been working fine. HTTP also working, as it showing correct test home page.

Please guide me.

Thanks.

Raihan

How to open access to all? So users can download files without login and password?

missing (minor tips) to get htpasswd: sudo apt-get install apache2-utils

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
February 14, 2014

@fcenteno16: Where do you get that error?

I have a problem… I recieve the error 505… Can you help me?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.