How to Setup & Configure a WebDAV Server on Ubuntu Linux and Apache

This tutorial shows how to install and configure a Web Distributed Authoring and Versioning (WebDAV) server on modern Ubuntu Linux using Apache or Apache2. The WebDAV protocol is an OSI Application layer protocol that extends the Hypertext Transfer Protocol (HTTP). The WebDAV protocol is a writeable and collaborative medium beyond the read-only scope. Most modern operating systems and HTTP servers support WebDAV and security extensions for TLS and SSL. I recently had to set up a WebDAV server fast for research purposes; however, I did not know where to start. Below are the following steps I used to install and configure a quick WebDAV server on Ubuntu Linux using Apache2. First, let’s understand what WebDAV is and how this protocol contributes to the modern information-sharing technology environment.

What is Web Distributed Authoring and Versioning (WebDAV)?

The WebDAV protocol is an extension of the Hypertext Transfer Protocol (HTTP), which allows users to share, edit, copy, manage, and move files through a web server. Using features such as file locking and revision tracking, WebDAV can also support applications that rely on collaboration such as WinSCP. Today, many web servers and services such as Apache, Microsoft IIS, and Nginx and modern web browsers such as Google Chrome, Microsoft Edge, and Mozilla Firefox understand the WebDAV protocol. In the operating system landscape, modern operating systems such as Linux, *BSD, MacOS, Microsoft Windows, and web browsers such as Google Chrome, Microsoft Edge, and Mozilla Firefox all understand.

Apache2 Web Server Installation on Ubuntu

Since WebDAV is an extension of the Hypertext Transfer Protocol (HTTP) protocol we need a web server with an extension for WebDAV, we will use Apach2 on Ubuntu Linux. To use WebDAV on Ubuntu with Apache, we need to install and configure Apache with a WebDav directory.

Run the following commands to update Ubuntu, install and configure Apache2, as well as setup the Apache WebDAV directory to serve content from:

sudo apt-get update && sudo apt-get upgrade

sudo apt-get install apache2

sudo mkdir /var/www/webdav

sudo chown -R www-data:www-data /var/www/

Let's explore some of these commands to understand their functionality. 

The command sudo apt-get update && sudo apt-get upgrade updates the package information and upgrades installed packages on Debian-like systems such as Ubuntu using the apt package manager. The first part of the command, sudo apt-get update, refreshes the local package database, ensuring that the system has the latest information on available packages. The second part of the command, sudo apt-get upgrade, installs the latest versions of the already installed packages. This keeps the system up-to-date with the latest security patches and improvements.

The command sudo apt-get install apache2 installs the Apache web server on the system. Apache is one of the most widely used web servers globally and is commonly employed to serve web content. Once installed, Apache can be configured to host websites, applications, or support features like WebDAV.

The command sudo mkdir /var/www/webdav creates a directory named "webdav" within the "/var/www/" path. This command is used to create a specific directory for hosting content that is accessible via the Apache web server which will be used to serve WebDAV content from.

The final command sudo chown -R www-data:www-data /var/www/ changes the ownership of the "/var/www/" directory and its contents to the user and group "www-data". This is a standard configuration for Apache, as it runs with the user and group "www-data" by default. This command ensures the web server has the necessary permissions to read and serve files from the specified directory.

WebDAV Installation on Apache Web Server

Run the following commands from the Linux command line to enable the WebDAV server on Ubuntu:

sudo a2enmod dav

sudo a2enmod dav_fs

sudo systemctl restart apache2

Let's explore these commands to understand them better during the WebDAV setup process. Two commands need to be executed to enable WebDAV functionality on an Apache web server. These commands are sudo a2enmod dav and sudo a2enmod dav_fs. The command sudo a2enmod dav activates the mod_dav Apache module, which is necessary for supporting the core features of WebDAV. WebDAV extends HTTP capabilities, enabling collaborative and remote content authoring. The second command, sudo a2enmod dav_fs, enables the mod_dav_fs module, which adds support for file system-based storage in the context of WebDAV. This allows users to interact with files and directories on the server using standard HTTP methods.

After enabling or modifying modules, it's crucial to restart the Apache web server (apache2) using the command sudo systemctl restart apache2. This step ensures that any changes made take effect by reloading the Apache configuration, including newly enabled WebDAV modules and other configurations. By executing these commands, you can set up the Apache server to support WebDAV, providing a robust platform for collaborative and remote content management.

Configure WebDAV on Apache

We need to add a few lines to the 000-default.conf which is the basic Apache file that controls the default sample site. Open the file with sudo using your text editor of choice, I will be using VIM.

sudo vim /etc/apache2/sites-available/000-default.conf

On the first line, add the following:

DavLockDB /var/www/DavLock

Next, we need to use the Alias directive to create a virtual path /webdav that maps to the physical directory /var/www/webdav. This means that when users access http://<WebDAV_SERVER>/webdav, Apache will serve content from the specified directory.

Next inside the VirtualHost tag add the following:

Alias /webdav /var/www/webdav

<Directory /var/www/webdav>

    DAV On

</Directory>

The <Directory> block defines settings that apply to the specified WebDAV directory we setup earlier (/var/www/webdav). Inside this block, we have the DAV On directive, which activates the WebDAV module for the specified directory.

Once added, run the following command: 

sudo systemctl restart apache2

This command will refresh the Apache2 and WebDAV server.

Accessing the Apache WebDAV Directory on Windows

To test out our WebDAV server, we can use a Windows machine such as Windows 11 to open a network adjacent to our WebDav folder. In a Windows Explorer window simply run the following command:

\\<IP of WebDAV Server>@80\webdav

This should open the WebDav share in Windows Explorer. Similarly, since WebDAV is an extension of HTTP you can access the Apache WebDAV share in a web browser with

http://<IP of WebDAV Server>@80/webdav

I hope you found this tutorial informative and helpful, feel free to follow me on social media for useful tutorials and how to’s.

Previous
Previous

NodeJS & ExpressJS: HTTP Requests Using the Google Chrome Devtools Console

Next
Next

How-to: Install Chromium (open-source Google Chrome) Web Browser on Ubuntu Linux (ARM64)