How To Set Up WebDAV With Lighttpd On Mandriva 2008.1

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2008-08-24 19:41. :: Mandriva | Lighttpd

How To Set Up WebDAV With Lighttpd On Mandriva 2008.1

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 08/08/2008

This guide explains how to set up WebDAV with lighttpd on a Mandriva 2008.1 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 lighttpd 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 Mandriva 2008.1 server with the IP address 192.168.0.100 here.

 

2 Installing WebDAV

Before we install any packages, we must enable the main, main_updates, contrib, and contrib_updates repositories. Go to http://easyurpmi.zarb.org/ - it should give you the commands you need to run to enable these repositories. In my case, I ran

urpmi.addmedia contrib ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/contrib/release with media_info/hdlist.cz

urpmi.addmedia --update contrib_updates ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/contrib/updates with media_info/hdlist.cz

urpmi.addmedia main ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/main/release with media_info/hdlist.cz

urpmi.addmedia --update main_updates ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/main/updates with media_info/hdlist.cz

You can install lighttpd (if it's not already installed), the lighttpd WebDAV module and the apache-base package (which contains the tool htpasswd which we will need later on to generate a password file for the WebDAV share) as follows:

urpmi lighttpd lighttpd-mod_webdav lighttpd-mod_auth apache-base

If you already have Apache installed, you should stop it now and remove Apache's system startup links so that it cannot interfere with lighttpd (you can run the following two commands even if you don't know if you have Apache installed):

/etc/init.d/httpd stop
chkconfig httpd off

Then we start lighttpd:

/etc/init.d/lighttpd start

Next, we open /etc/lighttpd/lighttpd.conf and enable/add the modules mod_alias, mod_webdav, and mod_auth in the server.modules stanza (it is important that mod_webdav is listed before mod_auth!):

vi /etc/lighttpd/lighttpd.conf

[...]
server.modules              = (
#                               "mod_rewrite",
#                               "mod_redirect",
                                "mod_alias",
                                "mod_access",
#                               "mod_cml",
#                               "mod_trigger_b4_dl",
                                "mod_webdav",
                                "mod_auth",
#                               "mod_status",
#                               "mod_setenv",
#                               "mod_fastcgi",
#                               "mod_proxy",
#                               "mod_simple_vhost",
#                               "mod_evhost",
#                               "mod_userdir",
#                               "mod_cgi",
#                               "mod_compress",
#                               "mod_ssi",
#                               "mod_usertrack",
#                               "mod_expire",
#                               "mod_secdownload",
#                               "mod_rrdtool",
                                "mod_accesslog" )
[...]

Restart lighttpd afterwards:

/etc/init.d/lighttpd restart

 

3 Creating A Virtual Host

I will now create a lighttpd vhost (www.example.com) in the directory /var/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 /var/www/web1/web and make the lighttpd user and group (they are named apache on Mandriva!) the owner of that directory:

mkdir -p /var/www/web1/web
chown apache:apache /var/www/web1/web

Then we open /etc/lighttpd/lighttpd.conf and add the following vhost to the end of the file:

vi /etc/lighttpd/lighttpd.conf

[...]
$HTTP["host"] == "www.example.com" {
  server.document-root = "/var/www/web1/web"
}

Afterwards we restart lighttpd:

/etc/init.d/lighttpd restart

 

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.

(Please don't use the -c switch if /var/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 /var/www/web1/passwd.dav file so that only root and the members of the apache group can access it:

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

Now we modify our vhost in /etc/lighttpd/lighttpd.conf so that it looks as follows:

vi /etc/lighttpd/lighttpd.conf

[...]
$HTTP["host"] == "www.example.com" {
  server.document-root = "/var/www/web1/web"
  alias.url = ( "/webdav" => "/var/www/web1/web" )
  $HTTP["url"] =~ "^/webdav($|/)" {
    dir-listing.activate = "enable"
    webdav.activate = "enable"
    webdav.is-readonly = "disable"
    auth.backend = "htpasswd"
    auth.backend.htpasswd.userfile = "/var/www/web1/passwd.dav"
    auth.require = ( "" => ( "method" => "basic",
                             "realm" => "webdav",
                             "require" => "valid-user" ) )
  }
}

The alias.url directive makes (together with $HTTP["url"] =~ "^/webdav($|/)") 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.

Restart lighttpd afterwards:

/etc/init.d/lighttpd restart

 

5 Testing WebDAV

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

urpmi cadaver

To test if WebDAV works, type:

cadaver http://www.example.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:

[root@server1 ~]# cadaver http://www.example.com/webdav/
Authentication required for webdav on server `www.example.com':
Username: test
Password:
dav:/webdav/> quit
Connection to `www.example.com' closed.
[root@server1 ~]#

 

6 Configure A Windows XP Client To Connect To The WebDAV Share

This is described on http://www.howtoforge.com/setting-up-webdav-with-apache2-on-debian-etch-p2.

Please specify the port in the WebDAV URL, e.g. http://www.example.com:80/webdav. For some strange reason this makes Windows XP accept the normal username (e.g. test) - otherwise Windows XP expects NTLM usernames (that would have the form www.example.com\test).

 

7 Configure A Linux Client (GNOME) To Connect To The WebDAV Share

This is described on http://www.howtoforge.com/setting-up-webdav-with-apache2-on-debian-etch-p3.

 

8 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.