How To Set Up WebDAV With Apache2 On Debian Etch

Version 1.0
Author: Falko Timme

This guide explains how to set up WebDAV with Apache2 on a Debian Etch server. WebDAV stands for Web-based Distributed Authoring and Versioning and is a set of extensions to the HTTP protocol that allow users to directly edit files on the Apache server so that they do not need to be downloaded/uploaded via FTP. Of course, WebDAV can also be used to upload and download files.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I'm using a Debian Etch server with the IP address 192.168.0.100 here.

 

2 Installing WebDAV

If Apache is not already installed, install it as follows:

apt-get install apache2

Afterwards, enable the WebDAV modules:

a2enmod dav_fs
a2enmod dav

Reload Apache:

/etc/init.d/apache2 force-reload

 

3 Creating A Virtual Host

I will now create a default Apache vhost in the directory /var/www/web1/web. For this purpose, I will modify the default Apache vhost configuration in /etc/apache2/sites-available/default. If you already have a vhost for which you'd like to enable WebDAV, you must adjust this tutorial to your situation.

First, we create the directory /var/www/web1/web and make the Apache user (www-data) the owner of that directory:

mkdir -p /var/www/web1/web
chown www-data /var/www/web1/web

Then we back up the default Apache vhost configuration (/etc/apache2/sites-available/default) and create our own one:

mv /etc/apache2/sites-available/default /etc/apache2/sites-available/default_orig
vi /etc/apache2/sites-available/default

NameVirtualHost *
<VirtualHost *>
        ServerAdmin [email protected]

        DocumentRoot /var/www/web1/web/
        <Directory /var/www/web1/web/>
                Options Indexes MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

</VirtualHost>

Then reload Apache:

/etc/init.d/apache2 reload

 

4 Configure The Virtual Host For WebDAV

Now we create the WebDAV password file /var/www/web1/passwd.dav with the user test (the -c switch creates the file if it does not exist):

htpasswd -c /var/www/web1/passwd.dav test

You will be asked to type in a password for the user test.

We will later on use the URL http://192.168.0.100/webdav to connect to WebDAV. When you do this on a Windows XP client and type in the user name test, Windows translates this to 192.168.0.100\test. Therefore we create a second user account now (without the -c switch because the password file is already existing):

htpasswd /var/www/web1/passwd.dav 192.168.0.100\\test

(We must use a second backslash here in the user name to escape the first one!)

Now we change the permissions of the /var/www/web1/passwd.dav file so that only root and the members of the www-data group can access it:

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

Now we modify our vhost in /etc/apache2/sites-available/default and add the following lines to it:

vi /etc/apache2/sites-available/default
[...]
        Alias /webdav /var/www/web1/web

        <Location /webdav>
           DAV On
           AuthType Basic
           AuthName "webdav"
           AuthUserFile /var/www/web1/passwd.dav
           Require valid-user
       </Location>
[...]

The Alias directive makes (together with <Location>) that when you call /webdav, WebDAV is invoked, but you can still access the whole document root of the vhost. All other URLs of that vhost are still "normal" HTTP.

The final vhost should look like this:

NameVirtualHost *
<VirtualHost *>
        ServerAdmin [email protected]

        DocumentRoot /var/www/web1/web/
        <Directory /var/www/web1/web/>
                Options Indexes MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        Alias /webdav /var/www/web1/web

        <Location /webdav>
           DAV On
           AuthType Basic
           AuthName "webdav"
           AuthUserFile /var/www/web1/passwd.dav
           Require valid-user
       </Location>
</VirtualHost>

Reload Apache afterwards:

/etc/init.d/apache2 reload

 

5 Testing WebDAV

We will now install cadaver, a command-line WebDAV client:

apt-get install cadaver

To test if WebDAV works, type:

cadaver http://localhost/webdav/

You should be prompted for a user name. Type in test and then the password for the user test. If all goes well, you should be granted access which means WebDAV is working ok. Type quit to leave the WebDAV shell:

server1:~# cadaver http://localhost/webdav/
Authentication required for test on server `localhost':
Username: test
Password:
dav:/webdav/> quit
Connection to `localhost' closed.
server1:~#

Share this page:

8 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By:

I hope that this help someone:

 http://ulihansen.kicks-ass.net/aero/webdav/

 ;-)

By: Gary Judge

Just a quick note to thank you for your tutorial. I've now just managed to get WebDav running on my Raspberry Pi. Cheers, Gary

By: Roman Liebich

Hello????

i am so sorry but i have got the question:

How can i get access to webdav only by username dialoge?

I hope you can help me. Thanks so mutch. great tutorial.

By

 

By: Cr00ksed

Hi,

 

I have a problem with Win 8.1, I have enabled the basic auth (by following this post : http://stackoverflow.com/questions/13413914/how-to-enable-basic-authentication-for-webdav-on-windows-8) but when I try to connect to my webdav using http://192.168.X.X/webdav windows tells me that the name entered seems to not exists. My webdav is working with another Linux distrib, on my Windows internet browser too...

Could you help ?

By: Felippe

Me too

By: John Steel

Putting the password file into /var/www is really a great idea!

By: David

When connecting with Cadaver, I get an error

[email protected]:/var/www/web1 $ cadaver http://localhost/webdav/

Could not access /webdav/ (not WebDAV-enabled?):

405 Method Not Allowed

Connection to `localhost' closed.

dav:!>

 

Any thoughts on what to check?

By: fullcane

Two remarks:

1. The file /etc/apache2/sites-available/default seems to have been renamed by default now. In my case, it is named /etc/apache2/sites-available/000-default.conf. I have adjusted things accordingly.

2. Apart from that, I precisely followed the procedure above, but ended up with a similar problem as David. In my case, calling cadaver results in 

Could not open collection:

404 Not Found

dav:/webdav/?

 

What to do now?