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

Sunday, May 25, 2014

?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.

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

Installing and configuring Apache2Securing Share Access with AuthenticationConfiguring WebDAV Virtual HostMapping share on windows

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

apt-get update && apt-get upgrade

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

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

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

mkdir /var/www/data
mkdir /var/www/data/general
mkdir /var/www/data/user1
mkdir /var/www/data/sales

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”
chown -R www-data:www-data /var/www/data/*

Next we need to create htpasswd file to provide the authentication

Initially create the .davpasswd file with user1

htpasswd -c /etc/apache2/.davpasswd user1

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

htpasswd /etc/apache2/.davpasswd user2

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

Restart Apachi2 service to apply the changes

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

nano /etc/apache2/sites-available/files.domainname.com
ServerName files.domainname.com
DocumentRoot /var/www/data/empty


Options none
AllowOverride None
Order allow,deny
allow from all

#General sharing

Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all

Alias /general /var/www/data/general

DAV On
AuthType Basic
AuthName “webdav”
AuthUserFile /etc/apache2/.davpasswd
Require valid-user

#Personal directory for user1

Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all

Alias /user1 /var/www/data/user1

DAV On
AuthType Basic
AuthName “user1?
AuthUserFile /etc/apache2/.davpasswd
Require user user1

#Shared directory for Sales

Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all

Alias /sales /var/www/data/sales

DAV On
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.

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.

Go to Computer and select Map network drive, and it’ll open up the wizard.Under path put https://files.domainname.com/user1 as you’ve configure the VirtualHost (make sure that you’ve configured your DNS settings for files.domainname.com)Check reconnect at logon and use different credentialsWhen it prompt for password type user1 and the password generated from htpasswd.

Now you have access to the shared drive :)

462 Views

View the original article here