Bobcares

Enabling WebDAV for Apache

by | Mar 24, 2006

Recently I had the opportunity to enable WebDav for an account in a Plesk 5.5 server that my team maintained. The machine was a RedHat 7.3 server on which ran Apache 1.3.27. The following article is a documentation of the questions I asked myself regarding WebDav.

I principally depended on the article by Martin Brown published in ServerWatch.com for the implementation. I highly recommended going through this article.

1. What is DAV?

As presented in RFC 2291, Distributed Authoring and Versioning aims to allow tools for remote loading, editing and saving (publishing) of various media types on the WWW to interoperate with any compliant Web server.

2. What is WebDav?

As an implementation of RFC 2291 in HTTP/1.1, RFC 2518 was presented, and the implementation was named “HTTP Extensions for Distributed Authoring” OR “WEBDAV”

Assuming that the brief introduction through the RFC articles was scary enough, I will now quote the definition of WebDav as given by Martin Brown.

“Web-based Distributed Authoring and Versioning (WebDAV) uses extensions to the existing HTTP protocol to enable multiple users to manage and modify the files in a remote system. Using suitably enabled clients you can view, open, edit and save files directly into the filesystem of the Web site as it were of a remote website.”

Which in essence means, the owner of the website can store documents on a shared folder which can be updated by visitors who have adquetly equipped client softwares. This access can be controlled by imposing a login restriction to that folder. A user will not be able to create a new document, only modify and save an existing one.

3. WebDav module for Apache

My area of interest in HTTP/1.1 is Apache. WebDav is implemented in Apache through mod_dav and was developed by IETF WEBDAV Working Group.

Now that you know all the back ground, lets move on to the next step of getting the mod_dav binary into the system.

First verify if it’s precompiled into the HTTP binary or loaded into the HTTPD instance through the default HTTPD configuration of the control panel. For that do:

httpd -l

AND

cat /proc/$(netstat -lpn | grep :80 |
awk '{print $NF}' |
cut -f1 -d/)/cmdline | perl -pe 's//n/g' | grep DAV

If you see a line that says “mod_dav.c” or “-DHAVE_DAV” respectively, voila! half the work is done for you. mod_dav is loaded in RAM and ready for operation.

Now you only need to configure the individual Virtual Host to activate a shared folder. So just skip to Step 6

If you do not have dav module loaded into RAM, lets see if the binary is present in the system compiled as a DSO module. For that look for the file libdav.so in your system’s Apache module directory. You can use the following command to know what your system’s Apache module directory is set to:

apxs -q LIBEXECDIR

NOTE: You need to give the full path to the APXS if it is not stored in your $PATH. In Plesk APXS is in /usr/sbin and in CPanel it is in /usr/local/apache/bin.

If you see that the binary is in your machine, skip to Step 5.

If you do not find the pre-compiled mod_dav binary, don’t lose heart… you have the golden opportunity to do it yourself.

4. Installing mod_dav

mod_dav can be downloaded from http://www.webdav.org/mod_dav/mod_dav-1.0.3-1.3.6.tar.gz

This can be either compiled as statically linked to Apache or as a dynamically loadable module. I went with the dynamic loading option by using the APXS tool. By default the configuration goes with this option.

So just do,

./configure
make
make install

Now the libdav.so binary will be copied into the Apache modules directory.

5. Loading WebDav module

mod_dav is loaded into memory by using the LoadModule directive. Give a line like the one below in your httpd.conf:

   LoadModule dav_module modules/libdav.so

NOTE: Make sure you are giving the correct module directory name. The module directory in Plesk is “modules” while in CPanel it is “libexec”. You have to find which one is your’s as detailed in step 3.

Quoting Martin Brown:

“To make use of WebDAV you must provide the location of a lock file (using the DAVLockDB directive) which will be used to record which user has a particular file open for writing or updating and prevents multiple users from trying to write to the same file. You can also specify a timeout value; Apache will automatically remove a lock if no access occurs during this period, the client specifies the requested timeout during connection, but you can override this using the DAVMinTimeout directive.”

The following two directives will suffice:

DAVLockDB /tmp/DAVLock
DAVMinTimeout 600

6. Creating a shared folder

Now to enable a shared directory in your client’s account, use the “Location” directive in httpd.conf. I’ll give the steps I did, so that you can learn from example.

mkdir /home/httpd/vhosts/XXXXXXX.com/httpdocs/webshare
chmod 775 /home/httpd/vhosts/XXXXXXX.com/httpdocs/webshare
chgrp apache /home/httpd/vhosts/XXXXXXX.com/httpdocs/webshare
htpasswd -c /home/httpd/vhosts/XXXXXXX.com/.DAVlogin

In the htpasswd command, you can set the login details to the shared folder.

NOTE: While using chgrp, I gave the group name of my web server. You should be giving your’s. TO find out your web server’s group, do the following command:

 grep "^Group" /etc/httpd/conf/httpd.conf

Substitute the path to config file with your system’s httpd config path.

Within the virtual host definition, I gave the following directives:

<Location /webshare/>
    DAV On
    AuthType Basic
    AuthName "Editing Restricted"
    AuthUserFile /home/httpd/vhosts/XXXXXXX.com/.DAVlogin
    <LimitExcept GET HEAD OPTIONS>

        Require user wbuser
    </LimitExcept>
</Location>

The LimitExcept setting specifies that anyone trying to edit any files inside the shared folder will need to provide the login details you specified using the htpasswd command.

If you don’t want any of these frills of security, omit the htpasswd command and just give the following directive:

<Location /webshare/>
DAV On
</Location>

Restart Apache and you should be ready to roll.

7. Testing WebDav functionality

Quoting Martin Brown:

“Under Windows, Windows 98, Me, 2000 and XP can all access a Web Share (the Microsoft term for a WebDAV-enabled directory). Use the Add a Network Place wizard, either through the links in the My Network Places window or through a standard File Open/Save dialog and enter the URL.”

If you enabled access restriction, you will have to give a username and password. If not, you will be directly logged in.



Articles by Visakh About the author:
Visakh S. Nair works as Engineer in Bobcares. He is a graduate in Computer Science and specialises in Plesk server administration.

0 Comments

Never again lose customers to poor
server speed! Let us help you.