Creating a WebDAV server on Debian or Ubuntu
Introduction
If you have a server on your local network that is used as a file storage and contains a great number of documents, you will probably not want to upload all of them into a web service and will continue working on them in the old manner. But there is a simple, reliable and secure solution that allows you to take advantage of editing documents online. You need to do the following:
Set up WebDAV on your server. WebDAV (Web Distributed Authoring and Versioning) is an extension of the HTTP protocol that allows to manage files on a remote server, access documents over the web and collaboratively work on them.
Step 1. Create and configure your WebDAV server on Ubuntu 14.04
Install the Apache web server
sudo apt-get update
sudo apt-get install apache2
Step 2. Set the WebDAV data directory
The default document root directory for Apache (in Ubuntu 14.04 and later) is /var/www/html. It makes up the document tree structure which should be accessible from the web. Create a new folder named webdav within the /var/www/ directory:
sudo mkdir /var/www/webdav
Change the folder owner to your Apache user www-data so that Apache has write access to the folder:
sudo chown -R www-data:www-data /var/www/
Step 3. Enable the WebDAV modules within the Apache configuration
Apache includes built-in WebDAV modules, but they are not enabled by default. Enable them using the following commands:
sudo a2enmod dav
sudo a2enmod dav_fs
Step 4. Configure your WebDAV Server
Initial configuration
Open the configuration file in a text editor, e.g. nano:
sudo nano /etc/apache2/sites-available/000-default.conf
Add the following directive as a first line:
DavLockDB /var/www/DavLock
Find the section and add the following directives within it:
Alias /webdav /var/www/webdav
<Directory /var/www/webdav>
DAV On
</Directory>
- The DavLockDB directive specifies the path to the WebDAV lock database.
- The Alias directive makes it possible to allow web access to any folder outside of the document root. In this example it maps requests to http:///webdav to the /var/www/webdav folder.
- The Directory directive sets a number of other directives that should be applied to the specified folder and all its contents. In this case, the DAV directive is specified that WebDAV should be enabled for the /var/www/webdav folder. Edit the Apache configuration file Save the changes and close the file. Now your WebDAV server is almost ready to use, but we need to make it more secure by enabling authentication.
Enabling authentication
Select the necessary authentication type depending on the following two conditions:
No matter which authentication type you want to enable, first install the apache2-utils utilities for your web server. This set of programs comprises both the htpasswd utility used to create a password file for the basic authentication and the htdigest utility that is used to create a password file for the digest authentication.
sudo apt-get install apache2-utils
Step 5. Create a password file
Generate the file that contains user passwords adding the first user:
For the Basic authentication:
sudo htpasswd -c /etc/apache2/webdav.passwords alex
For the Digest authentication:
sudo htdigest -c /etc/apache2/webdav.passwords webdav alex
You will be prompted to set and confirm a new password for the specified user.
When adding other users, use the same command omitting the -c flag:
For the Basic authentication:
sudo htpasswd /etc/apache2/webdav.passwords chris
For the Digest authentication:
sudo htdigest /etc/apache2/webdav.passwords webdav chris
Change the owner of the password file to www-data so that Apache can read the file:
sudo chown www-data:www-data /etc/apache2/webdav.passwords
Step 6. Edit the Apache configuration file
Open the configuration file in a text editor, e.g. nano:
sudo nano /etc/apache2/sites-available/000-default.conf
Add the following lines to the <Directory> section:
For the Basic authentication:
AuthType Basic
AuthName "webdav"
AuthUserFile /etc/apache2/webdav.passwords
Require valid-user
For the Digest authentication:
AuthType Digest
AuthName "webdav"
AuthUserFile /etc/apache2/webdav.passwords
Require valid-user
- The AuthType directive sets the authentication type that should be used when users try to access the /var/www/webdav directory. The possible values are Basic or Digest.
- The AuthName directive specifies the name of the authentication realm. The specified value should be displayed in the browser password dialog so that the user knows which credentials to provide. When enabling Digest authentication, this value is also included into the command used for the password file creation and acts as a namespace for users.
- The AuthUserFile directive specifies the path to the file that contains the list of users and their passwords.
- The Require directive checks if authenticated users are authorized to access the directory according to the certain restrictions. In this case, it specifies that all valid users (i.e. the users who can verify their identity) can access the directory.
Step 7. Save the changes made and close the file.
Apply the changes
Enable the selected authentication module.
For the Basic authentication:
sudo a2enmod auth_basic
For the Digest authentication:
sudo a2enmod auth_digest
Restart the Apache server using the following command so that the changes take effect:
sudo service apache2 restart
Verify that your WebDAV directory is accessible from an external computer:
Your WebDAV server can be accessed at http:// < hostname>/webdav