Posted By Irfad

How to Setup WebDAV Based File Server Using Apache2 on Ubuntu 12.04

Hi fellas, after a while going to write about setting up a WebDAV based file sharing system. What’s WebDAV? Well, to make it simple it’s a protocol for read write access to the file system works in conjunction with http web services. Somewhat similar to ftp access.

One advantage using this setup is you can enable HTTPS and make the transition more secure. And you can also map as a network drive on windows with native drive mapping tool.

What do you need?

An Ubuntu server 12.04 (you can get a 5$ VPS to meddle with)
The know-how on Linux and Apache2 web server

As we have to go through several steps, I’ve divided the setup into following four simple parts

  1. Installing and configuring Apache2
  2. Securing Share Access with Authentication
  3. Configuring WebDAV Virtual Host
  4. Mapping share on windows

Installing and configuring Apache2

All commands are executed as root. To become root type “sudo su -” and provide your password.

Login to the server and make sure to update the packages to the latest packages

[box]apt-get update && apt-get upgrade[/box]

Install Apache2 web server. Simplest way is to setup LAMP stack with single command.

[box]apt-get install lamp-server^ (don’t forget ^ at the end)[/box]

Create directories to share assuming we need three directories to provide different permission level for users.

[box]mkdir /var/www/data
mkdir /var/www/data/general
mkdir /var/www/data/user1
mkdir /var/www/data/sales[/box]

Description of shares

general share is accessible by all users whom are restricted to the available users in the password list.
user1 share is accessible only by user1
sales share is accessible by user1 and user2

These folders should be given full web user permission which is “www-data”
[box]chown -R www-data:www-data /var/www/data/*[/box]

Securing Share Access with Authentication

Next we need to create htpasswd file to provide the authentication

Initially create the .davpasswd file with user1

[box]htpasswd -c /etc/apache2/.davpasswd user1[/box]

You can add as many users as you want by using the same command exluding the “-c” switch.

[box]htpasswd /etc/apache2/.davpasswd user2[/box]

Configuring WebDAV Virtual Host

Moving onto second part. This is where you point the share directories that can be accessed through http (WebDAV). I’ll cover setting up HTTPS and SSL in another article.

First enable WebDAV mod for apache2

[box]a2enmod dav
a2enmod dav_fs[/box]

Restart Apachi2 service to apply the changes

[box]service apache2 restart[/box]

Now create and edit the Virtual Host file with your favorite text editor. I use nano in this case

[box]nano /etc/apache2/sites-available/[/box]

[box]<VirtualHost *:80>
DocumentRoot /var/www/data/empty

<Directory /var/www/data/empty>
Options none
AllowOverride None
Order allow,deny
allow from all

#General sharing
<Directory /var/www/data/general>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all

Alias /general /var/www/data/general
<Location /general>
AuthType Basic
AuthName “webdav”
AuthUserFile /etc/apache2/.davpasswd
Require valid-user

#Personal directory for user1
<Directory /var/www/data/user1>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all

Alias /user1 /var/www/data/user1
<Location /user1>
AuthType Basic
AuthName “user1”
AuthUserFile /etc/apache2/.davpasswd
Require user user1

#Shared directory for Sales
<Directory /var/dav/accounting>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all

Alias /sales /var/www/data/sales
<Location /sales>
AuthType Basic
AuthName sales
AuthUserFile /etc/apache2/.davpasswd
Require user user1 user2

Looking at above example there are three different set of configurations

a. Under General share I’ve mentioned “Require valid-user” which means any username listed in the .davpasswd file can access the general share

b. For user1 “Require user user1” is configured so that only user1 has access to user1 share

c. For Sales share I’ve mentioned “Require user user1 user2”, this means both users can access the share and we can assign any user we want by appending to the configuration separated by space.

Once you’ve saved the configuration restart the service to apply the changes.

[box]service apache2 restart[/box]

Mapping share on windows

Alright configuration on the server side is done and we should be able to map the share on Windows, Linux and Mac clients. I’m only covering Windows here.

  1. Go to Computer and select Map network drive, and it’ll open up the wizard.
  2. Under path put as you’ve configure the VirtualHost (make sure that you’ve configured your DNS settings for
  3. Check reconnect at logon and use different credentials
  4. When it prompt for password type user1 and the password generated from htpasswd.

Now you have access to the shared drive 🙂

View Comments
View Comments
There are currently no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.