There is a new version of this tutorial available for openSUSE 12.2.

How To Set Up WebDAV With Apache2 On OpenSUSE 11.3

Version 1.0
Author: Falko Timme
Follow me on Twitter

This guide explains how to set up WebDAV with Apache2 on an OpenSUSE 11.3 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 an OpenSUSE 11.3 server with the IP address 192.168.0.100 here.

 

2 Installing WebDAV

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

yast2 -i apache2

Afterwards, enable the WebDAV modules:

a2enmod dav
a2enmod dav_fs
a2enmod dav_lock

Then create the system startup links for Apache and start it:

chkconfig --add apache2
/etc/init.d/apache2 start

 

3 Creating A Virtual Host

I will now create an Apache vhost www.example1.com in the directory /srv/www/web1/web. 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 /srv/www/web1/web and make the Apache user (wwwrun) and group (www) the owner of that directory:

mkdir -p /srv/www/web1/web
chown wwwrun:www /srv/www/web1/web

Now we create the Apache vhost for www.example1.com:

vi /etc/apache2/vhosts.d/www.example1.com.conf
<VirtualHost *>
        ServerAdmin webmaster@localhost
        ServerName www.example1.com
        ServerAlias example1.com

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

</VirtualHost>

Open /etc/apache2/httpd.conf and add the line NameVirtualHost * before the Include /etc/apache2/vhosts.d/*.conf line:

vi /etc/apache2/httpd.conf
[...]
### Virtual server configuration ############################################
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
NameVirtualHost *

Include /etc/apache2/vhosts.d/*.conf
[...]

Then restart Apache:

/etc/init.d/apache2 restart

 

4 Configure The Virtual Host For WebDAV

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

htpasswd2 -c /srv/www/web1/passwd.dav test

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

(Please don't use the -c switch if /srv/www/web1/passwd.dav is already existing because this will recreate the file from scratch, meaning you lose all users in that file!)

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

chown root:www /srv/www/web1/passwd.dav
chmod 640 /srv/www/web1/passwd.dav

Now we modify our vhost www.example1.com in /etc/apache2/vhosts.d/www.example1.com.conf and add the following lines to it:

vi /etc/apache2/vhosts.d/www.example1.com.conf
[...]
        Alias /webdav /srv/www/web1/web

        <Location /webdav>
           DAV On
           AuthType Basic
           AuthName "webdav"
           AuthUserFile /srv/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:

<VirtualHost *>
        ServerAdmin webmaster@localhost
        ServerName www.example1.com
        ServerAlias example1.com

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

        Alias /webdav /srv/www/web1/web

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

Next we must specify the location of the WebDAV lock database. I want to have it in /var/lib/dav/ so I create that directory now:

mkdir /var/lib/dav/
chown wwwrun:www /var/lib/dav/

Open /etc/apache2/httpd.conf and add a DAVLockDB directive above the NameVirtualHost * line:

vi /etc/apache2/httpd.conf
[...]
### Virtual server configuration ############################################
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
<IfModule mod_dav_fs.c>
# Location of the WebDAV lock database.
DAVLockDB /var/lib/dav/lockdb
</IfModule>
NameVirtualHost *

Include /etc/apache2/vhosts.d/*.conf
[...]

Restart Apache afterwards:

/etc/init.d/apache2 restart

 

5 Testing WebDAV

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

yast2 -i cadaver

To test if WebDAV works, type:

cadaver http://www.example1.com/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://www.example1.com/webdav/
Authentication required for webdav on server `www.example1.com':
Username: test
Password:
dav:/webdav/> quit
Connection to `www.example1.com' closed.
server1:~ #

You can now start using WebDAV as described in the chapters 6 and 7 of the tutorial How To Set Up WebDAV With Apache2 On Ubuntu 9.10. The WebDAV URL is http://www.example1.com/webdav/ for Linux clients and http://www.example1.com:80/webdav/ for Windows clients.

 

Share this page:

1 Comment(s)